Created
June 15, 2017 05:19
-
-
Save vijayanandrp/0d49c7f1b076783ea5e909c911cdf362 to your computer and use it in GitHub Desktop.
Writeup for InCTF 2014 - Crypto 100 - XOR decipher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import hashlib | |
| """ | |
| one.txt | |
| This sentence is encrypted using XOR cipher. | |
| """ | |
| plain_text = open('one.txt','r').read().strip() | |
| """ | |
| one.txt.enc | |
| LAcbGEUKHQEGDgsaHU8bGEUcFgwAEhUNHQtSHhYQFghSMyorWAwbGw0cCkE= | |
| """ | |
| cipher_text = open('one.txt.enc','r').read().decode("base64") | |
| print plain_text | |
| print '---------------------------------------------------------------------' | |
| print cipher_text | |
| print '---------------------------------------------------------------------' | |
| plain_text = [ord(i) for i in plain_text] | |
| cipher_text = [ord(i) for i in cipher_text] | |
| key = '' | |
| for i in range(len(plain_text)): | |
| c = ((plain_text[i] ^ cipher_text[i])) | |
| key += chr(c) | |
| print key | |
| print '---------------------------------------------------------------------' | |
| print 'VERFICIATION' | |
| key='xorkey' | |
| key_text = [ord(i) for i in key] | |
| msg = '' | |
| check = len(key_text) | |
| j=0 | |
| for i in range(len(cipher_text)): | |
| if check > j: | |
| c = ((key_text[j] ^ cipher_text[i])) | |
| msg+= chr(c) | |
| if j+1 == check: | |
| j=0 | |
| else: | |
| j+=1 | |
| print '--------------------------------------------------' | |
| print msg | |
| print '--------------------------------------------------' | |
| print '---------------------------------------------------------------------' | |
| print 'CAPTURE THE FLAG' | |
| key='xorkey' | |
| """ | |
| Second.txt.enc | |
| LAcXSz02Kk8RAhURHR1SAhZZGU8EDhcAWBgXCg5ZGwcdAgYcWAkdGUUYWAwbGw0cCk8TBQFZCwcdHgkdWAEdH0UQFk8CGQQaDAYRDktZLAcXSwMVGQhSDQoLWBsaAhZZFAoEDglZERxSHw0cWAsXCBcACBsbBAtZEwoLSwwNCwoeDUs= | |
| """ | |
| key_text = [ord(i) for i in key] | |
| cipher_text = open('two.txt.enc','r').read().decode("base64") | |
| cipher_text = [ord(i) for i in cipher_text] | |
| flag = '' | |
| check = len(key_text) | |
| j=0 | |
| for i in range(len(cipher_text)): | |
| if check > j: | |
| c = ((key_text[j] ^ cipher_text[i])) | |
| flag+= chr(c) | |
| if j+1 == check: | |
| j=0 | |
| else: | |
| j+=1 | |
| print '--------------------------------------------------' | |
| print flag | |
| print '--------------------------------------------------' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment