Skip to content

Commit

Permalink
crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
Brock committed Dec 19, 2014
1 parent b4d288b commit ef7627c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Binary file added crypto/tmp
Binary file not shown.
21 changes: 21 additions & 0 deletions crypto/xor_dec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sys

key_len = int(sys.argv[2])
def xor_str(str1, str2, length):
#print str1, str2, length
output = ''
for i in range(length):
output += chr(ord(str1[i]) ^ ord(str2[i]))
return output

with open(sys.argv[1]) as f:
buf = f.read()

output = ''
for i in range(0, len(buf), key_len):
#print i
str1 = buf[i: i + key_len]
str2 = buf[i + key_len: i + key_len * 2]
output += xor_str(str1, str2, min(len(str1), len(str2)))
print output

14 changes: 14 additions & 0 deletions crypto/xor_enc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys

crypto = sys.argv[2]
with open(sys.argv[1]) as f:
buf = f.read()

output = ''
i = 0
for c in buf:
output += chr(ord(c) ^ ord(crypto[i % len(crypto)]))
i += 1

sys.stdout.write(output)

0 comments on commit ef7627c

Please sign in to comment.