import t # 01234567890123 s = "this is a test of ctr encryption and editing that's long enough to roll the ctr a couple of times and that." s1 = "this is a TEST of ctr encryption and editing that's long enough to roll the ctr a couple of times and that." k = "yellow submarine" e = t.encrypt_aes_128_ctr(s, k) e1 = t.edit_ctr_stream(e, 10, "TEST", k) assert t.decrypt_aes_128_ctr(e1, k) == s1 F = open('25.txt', 'r') s = ''.join(F.readlines()).replace('\r', '').replace('\n', '') F.close() s = t.decrypt_aes_128_ecb(t.base64_to_str(s), "YELLOW SUBMARINE") o = t.CTRVictim(s, t.random_aes_key()) # use edit() to replace whole file with AAAA original_cipher = o.get_ciphertext() o.edit(0, "A" * len(original_cipher)) # xor ciphertext with AAAA to get encrypted keystream keystream = t.fixed_xor(o.get_ciphertext(), "A" * len(original_cipher)) # xor encrypted keystream with original ciphertext to get plaintext plaintext = t.fixed_xor(keystream, original_cipher) print plaintext assert plaintext == s
import t F = open('20.txt', 'r') data = F.readlines() F.close() key = t.random_aes_key() r = [t.encrypt_aes_128_ctr(t.base64_to_str(d.replace('\r', '').replace('\n', '')), key) for d in data] s = t.defeat_fixed_nonce_ctr_stats(r) print '\n'.join(s) print len(s)
import t secret = t.base64_to_str( "Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBqdXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK" ) print t.defeat_ecb_fixed_key_with_oracle(secret)
import t secret = t.base64_to_str("Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBqdXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK") print t.defeat_ecb_fixed_key_with_oracle(secret)
"MDAwMDAxV2l0aCB0aGUgYmFzcyBraWNrZWQgaW4gYW5kIHRoZSBWZWdhJ3MgYXJlIHB1bXBpbic=", "MDAwMDAyUXVpY2sgdG8gdGhlIHBvaW50LCB0byB0aGUgcG9pbnQsIG5vIGZha2luZw==", "MDAwMDAzQ29va2luZyBNQydzIGxpa2UgYSBwb3VuZCBvZiBiYWNvbg==", "MDAwMDA0QnVybmluZyAnZW0sIGlmIHlvdSBhaW4ndCBxdWljayBhbmQgbmltYmxl", "MDAwMDA1SSBnbyBjcmF6eSB3aGVuIEkgaGVhciBhIGN5bWJhbA==", "MDAwMDA2QW5kIGEgaGlnaCBoYXQgd2l0aCBhIHNvdXBlZCB1cCB0ZW1wbw==", "MDAwMDA3SSdtIG9uIGEgcm9sbCwgaXQncyB0aW1lIHRvIGdvIHNvbG8=", "MDAwMDA4b2xsaW4nIGluIG15IGZpdmUgcG9pbnQgb2g=", "MDAwMDA5aXRoIG15IHJhZy10b3AgZG93biBzbyBteSBoYWlyIGNhbiBibG93" ] iv = t.random_aes_key() s = t.encrypt_random_cbc(data, iv) assert t.check_cbc_padding(s, iv), "oops" r = t.defeat_cbc_padding_oracle(s, iv) print repr(r) print t.base64_to_str(r) out = [] for d in data: iv = t.random_aes_key() s = t.encrypt_random_cbc([d], iv) out.append(t.base64_to_str(t.defeat_cbc_padding_oracle(s, iv))) out.sort() print '\n'.join(out)
import t s = "L77na/nrFsKvynd6HzOoG7GHTLXsTVu9qvY/2syLXzhPweyyMTJULu/6/kXX0KSvoOLSFQ==" r = t.decrypt_aes_128_ctr(t.base64_to_str(s), "YELLOW SUBMARINE") print r
data = [ "MDAwMDAwTm93IHRoYXQgdGhlIHBhcnR5IGlzIGp1bXBpbmc=", "MDAwMDAxV2l0aCB0aGUgYmFzcyBraWNrZWQgaW4gYW5kIHRoZSBWZWdhJ3MgYXJlIHB1bXBpbic=", "MDAwMDAyUXVpY2sgdG8gdGhlIHBvaW50LCB0byB0aGUgcG9pbnQsIG5vIGZha2luZw==", "MDAwMDAzQ29va2luZyBNQydzIGxpa2UgYSBwb3VuZCBvZiBiYWNvbg==", "MDAwMDA0QnVybmluZyAnZW0sIGlmIHlvdSBhaW4ndCBxdWljayBhbmQgbmltYmxl", "MDAwMDA1SSBnbyBjcmF6eSB3aGVuIEkgaGVhciBhIGN5bWJhbA==", "MDAwMDA2QW5kIGEgaGlnaCBoYXQgd2l0aCBhIHNvdXBlZCB1cCB0ZW1wbw==", "MDAwMDA3SSdtIG9uIGEgcm9sbCwgaXQncyB0aW1lIHRvIGdvIHNvbG8=", "MDAwMDA4b2xsaW4nIGluIG15IGZpdmUgcG9pbnQgb2g=", "MDAwMDA5aXRoIG15IHJhZy10b3AgZG93biBzbyBteSBoYWlyIGNhbiBibG93" ] iv = t.random_aes_key() s = t.encrypt_random_cbc(data, iv) assert t.check_cbc_padding(s, iv), "oops" r = t.defeat_cbc_padding_oracle(s, iv) print repr(r) print t.base64_to_str(r) out = [] for d in data: iv = t.random_aes_key() s = t.encrypt_random_cbc([d], iv) out.append(t.base64_to_str(t.defeat_cbc_padding_oracle(s, iv))) out.sort() print '\n'.join(out)
"U2hlIHJvZGUgdG8gaGFycmllcnM/", "VGhpcyBtYW4gaGFkIGtlcHQgYSBzY2hvb2w=", "QW5kIHJvZGUgb3VyIHdpbmdlZCBob3JzZS4=", "VGhpcyBvdGhlciBoaXMgaGVscGVyIGFuZCBmcmllbmQ=", "V2FzIGNvbWluZyBpbnRvIGhpcyBmb3JjZTs=", "SGUgbWlnaHQgaGF2ZSB3b24gZmFtZSBpbiB0aGUgZW5kLA==", "U28gc2Vuc2l0aXZlIGhpcyBuYXR1cmUgc2VlbWVkLA==", "U28gZGFyaW5nIGFuZCBzd2VldCBoaXMgdGhvdWdodC4=", "VGhpcyBvdGhlciBtYW4gSSBoYWQgZHJlYW1lZA==", "QSBkcnVua2VuLCB2YWluLWdsb3Jpb3VzIGxvdXQu", "SGUgaGFkIGRvbmUgbW9zdCBiaXR0ZXIgd3Jvbmc=", "VG8gc29tZSB3aG8gYXJlIG5lYXIgbXkgaGVhcnQs", "WWV0IEkgbnVtYmVyIGhpbSBpbiB0aGUgc29uZzs=", "SGUsIHRvbywgaGFzIHJlc2lnbmVkIGhpcyBwYXJ0", "SW4gdGhlIGNhc3VhbCBjb21lZHk7", "SGUsIHRvbywgaGFzIGJlZW4gY2hhbmdlZCBpbiBoaXMgdHVybiw=", "VHJhbnNmb3JtZWQgdXR0ZXJseTo=", "QSB0ZXJyaWJsZSBiZWF1dHkgaXMgYm9ybi4=" ] key = t.random_aes_key() r = [t.encrypt_aes_128_ctr(t.base64_to_str(d), key) for d in data] # why don't i just take the first block of each and treat as 40 blocks of repeating key xor ? ... s = t.defeat_fixed_nonce_ctr(r) print s print len(s)
import t F = open('20.txt', 'r') data = F.readlines() F.close() key = t.random_aes_key() r = [ t.encrypt_aes_128_ctr( t.base64_to_str(d.replace('\r', '').replace('\n', '')), key) for d in data ] s = t.defeat_fixed_nonce_ctr_stats(r) print '\n'.join(s) print len(s)