Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: UTF-8 -*-
- string = "something something something"
- key = "cheese"
- def crypt(string, key):
- data = ''
- for i in range(len(string)):
- # XOR
- xc = ord(string[i]) ^ ord(key[i%len(key)])
- # Convert XOR to base 2
- xc = bin(xc)[2:].zfill(8)
- data += str( xc )
- #print string[i]
- return data
- def decrypt(string, key):
- data = ''
- for i in range( (len(string)+1) / 8):
- # Convert each 8 bits to base 10
- x = int( string[((i+1)*8)-8:(i+1)*8], 2 )
- # XOR with key
- data += chr( x ^ ord(key[i%len(key)]) )
- return data
- print "String: %s - Key: %s \n \n%s\n" % (string, key, "="*10)
- x = crypt(string, key)
- print x + "\n"
- y= decrypt(x, key)
- print y + "\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement