Sunday, September 20, 2015

Python CodeHack | ROT13 function in different ways


"ROT13 ("rotate by 13 places", sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the letter 13 letters after it in the alphabet. ROT13 is a special case of the Caesar cipher, developed in ancient Rome." -- Wikipedia

In this post I will share the different ways to encode a string using ROT13 in Python, or better say in how mane ways you can do so in Python. We will show three ways to perform ROT13. 

1. First Approach
We make use of the maketrans function in string module.

import string

def rot13(text):
   if isinstance(text, str):
       rot13 = string.maketrans("ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz",
                                "NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm")
       
       return string.translate(text, rot13)
   else:
       raise ValueError("The parameter must be a string.")

2. Second Approach
But the problem with the above solution is that maketrans was removed in Python3. Instead we can use bytes.maketrans() for the purpose, so in order to obtain a more generalised solution we can do it as follows :-

import string
import sys


def rot13(text):
    if isinstance(text, str):
        if sys.version[0] == "2":
            rot13_data = string.maketrans("ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz",
                                          "NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm")
            return string.translate(text, rot13_data)
        elif sys.version[0] == "3":
            rot13_data = bytes.maketrans(b"ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz",
                                         b"NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm")
        return text.translate(rot13_data)
    else:
        raise ValueError("The parameter must be a string.")

You can simple send your rot13 cipher/plaintext and it will encode or decode accordingly.
3. Third Approach

Another better technique is to use codecs module and use the in built rot_13 encoding scheme which is the same. Also its more preferable.

import codecs

cipher = codecs.encode("Natsu Dragneel", "rot_13")
print(cipher)

plain = codecs.decode(cipher, "rot_13")
print(plain)
Continue Reading →

Python Code for Maximum Sum Subarray Problem

"In computer science, the maximum subarray problem is the task of finding the contiguous subarray within a one-dimensional array of numbers (containing at least one positive number) which has the largest sum. For example, for the sequence of values −2, 1, −3, 4, −1, 2, 1, −5, 4; the contiguous subarray with the largest sum is 4, −1, 2, 1, with sum 6." --Wikipedia

A linear time solution was proposed by Jay Kadane and was hence forth named as Kadane's Algorithm. The algorithm paradigm followed is Dynamic Programming. Here I have given you the python code for this problem.



Continue Reading →

Thursday, September 17, 2015

Must See | TEDx Talks Related to Computer Science, IT, and Technology

TED (http://www.ted.com/) Talks are very very inspiring for anyone irrespective of their religion, caste, age, education, position, relation, etc. The talks are given by high profile people that include, Scientists, Sociologist, Researchers, Philosophers, World leaders, professors etc.

These talks are in depth analysis of truth and science, Philosophy and belief, also the lectures varies vividly and ranges in a great span of subjects or topics or issues. In this post I have listed the very best TEDx Talks which have inspired me, these videos are very exciting and motivational. So I hope you enjoy!







I hope you like the video collection. I will update this post soon. If you have a link you would like to see in the above collection then please comment below and they will be added if appropriate.
Continue Reading →

Monday, September 14, 2015

FAIDDS | Forensic Acquisition Information and Drive Data Script

Forensic Acquisition Information and Drive Data Script

The script provides a simple way to gather drive information and acquire a drive from a specified device file to the local directory. For this script to work you must run it as Administrator.

Use the -d argument to specify the device or file path. Using -lh you can get the list of hashes available. These two options are mutually exclusive.
You can get sample reports in the Sample directory.

Get the Script

You can get the script easily by either downloading the project release, extracting the content and then running the script, alternatively clone the project using Git as shown in the image below.


After you have done so, move to the faidds directory and run the script faidds.py. Follow the example usages stated below for better understanding of how to use the script.
See all the available options

python faids.py --help

usage: faidds.py [-h] [-d DRIVE] [-D] [-c CHUNK] [-s SERIAL] [-m HASHES] [-lh]
             [-dcfldd]

Forensic Acquisition Information and Drive Data Script. This script provides a
simple way to gather drive information and acquire a drive from a specified
device file to the local directory. For this script to work you must run it as
Administrator. Use the -d argument to specify the device or file path. Using
-lh you can get the list of hashes available. These two options are mutually
exclusive.

optional arguments:
  -h, --help            show this help message and exit
  -d DRIVE, --drive DRIVE
                        Device file to acquire. Example: /dev/sda
  -D, --DEBUG           Debug mode will be activated. All the system calls are
                        printed
  -c CHUNK, --chunk CHUNK
                        Size to split file in GB (1024*1024*1024)
  -s SERIAL, --serial SERIAL
                        User specified serial number. Default is to find
                        serial number in drive info.
  -m HASHES, --hashes HASHES
                        List of hash algorithms to use. Comma separated with
                        no spaces. (default: md5)
  -lh, --list_hashes    List all the Hashes
  -dcfldd, --dcfldd     Use dcfldd to acquire image. (default: dc3dd)

Example Usage

Acquire a drive image and gather information

python faids.py -d /dev/sdb1 
Acquire a drive image and get multiple hash results

Write the hashes as Comma separated value.

python faids.py -d /dev/sdb1 -m md5,sha256,sha512
Get list of all available hashes

python faids.py -lh
Available hashes: md5, sha1, sha256, sha384 and sha512

Note

This script was adopted from here. I have refactored it and made it more readable with a better documentation and I plan to add some more new features later.

The code is hackable and you can add many more new features to the script. I hope you liked this post. Share this post, and leave a comment.

Thank you,
Sincerely,
Psycho_Coder.
Continue Reading →

Monday, September 7, 2015

[Research Paper] A Heuristic Approach to Factoid Question Generation from Sentence

 
Abstract: Question Generation (QG) and Question Answering (QA) are among the many challenges in natural language generation and natural language understanding. An automated QG system focuses on generation of expressive and factoid questions which assist in meetings, customer helpline, specific domain services, and Educational Institutes etc. In this paper, the proposed system addresses the generation of factoid or wh-questions from sentences in a corpus consisting of factual, descriptive and unbiased details. We discuss our heuristic algorithm for sentence simplification or pre-processing and the knowledge base extracted from previous step is stored in a structured format which assists us in further processing. We further discuss the sentence semantic relation which enables us to construct questions following certain recognizable patterns among different sentence entities, following by the evaluation of question generated.

Continue Reading →

Sunday, September 6, 2015

Online Hash Generator with PHP Source Code

It's an old little project that I made just to kill time, nothing more. Take the code and hack it in every way you want :D,

[Image: aOMecsk.png] 
Result:

[Image: qN2iBNJ.png]

 The Project is OpenSource and hosted on github : https://github.com/AnimeshShaw/Online-Hash-Generator

Before trying it yourself please read the HelpDocs: https://github.com/AnimeshShaw/Online-Hash-Generator/wiki/Help-Docs
 
Continue Reading →

Peter de Jong Attractor in Python

It's pretty simple and I have specially given the code in python which demonstrates the concept. For details on Attractors please refer wikipedia. I have used the Python pygame module for graphics.

Here's the end result:-

[Image: GOVr9W9.png]

Here's the code:


I have used two custom fonts as you can see in the code above. You can get them from here and here. You can use either system font or download two new fonts and put them in the same execution directory. Make sure you edit the code with proper font names. 

self.xn, self.yn = ( sin( self.constants["a"] * self.yn ) - cos ( self.constants["b"] \
                                   * self.xn ) ), ( sin( self.constants["c"] * self.xn ) - cos( self.constants["d"] * self.yn ) )
                   #  xn, yn = ( d * sin( a * xn ) - sin ( b * yn ) ), ( c * cos( a * xn ) + cos( b * yn ) )
                   self.coords.append( ( self.xn, self.yn ) )
                   pygame.draw.circle( self.screen, self.grayshade , ( self.width // 2 + \
                                           int( 120 * self.xn ), self.height // 2 + int( 120 * self.yn ) ), 1, 1 )
Changing the constants a,b, c and varying the number of iteration you can create many more custom shapes. So be creative and start hacking!
Continue Reading →

Follow Me!

Followers

Visitor Map