diff --git a/hw1.1/1a.py b/hw1.1/1a.py index 337b95b..dc90bd0 100644 --- a/hw1.1/1a.py +++ b/hw1.1/1a.py @@ -1,3 +1,5 @@ +import sys + with open("3/forstudents/a/ciphertext.bin", "rb") as cipher_file, open( "3/forstudents/a/key.bin", "rb" ) as key_file: @@ -5,6 +7,6 @@ with open("3/forstudents/a/ciphertext.bin", "rb") as cipher_file, open( key_content = key_file.read() print( (( - int.from_bytes(cipher_content, "big") ^ int.from_bytes(key_content, "big") - ).to_bytes(max(len(cipher_content), len(key_content)), "big")).decode() + int.from_bytes(cipher_content, sys.byteorder) ^ int.from_bytes(key_content, sys.byteorder) + ).to_bytes(max(len(cipher_content), len(key_content)), sys.byteorder)).decode() ) diff --git a/hw1.1/1b.py b/hw1.1/1b.py index 4362881..e75cfea 100644 --- a/hw1.1/1b.py +++ b/hw1.1/1b.py @@ -1,3 +1,5 @@ +import sys + with open("3/forstudents/b/ciphertext1.bin", "rb") as cipher1_file, open( "3/forstudents/b/ciphertext2.bin", "rb" ) as cipher2_file, open("3/forstudents/b/plaintext1.txt", "r") as plain_unknown_file: @@ -6,14 +8,14 @@ with open("3/forstudents/b/ciphertext1.bin", "rb") as cipher1_file, open( plain_unknown_content = plain_unknown_file.read() possible_key = ( - int.from_bytes(cipher1_content, "big") - ^ int.from_bytes(bytes(plain_unknown_content, "utf-8"), "big") - ).to_bytes(max(len(cipher1_content), len(plain_unknown_content)), "big") + int.from_bytes(cipher1_content, sys.byteorder) + ^ int.from_bytes(bytes(plain_unknown_content, "utf-8"), sys.byteorder) + ).to_bytes(max(len(cipher1_content), len(plain_unknown_content)), sys.byteorder) print( ( ( - int.from_bytes(cipher2_content, "big") - ^ int.from_bytes(possible_key, "big") - ).to_bytes(max(len(cipher2_content), len(possible_key)), "big") + int.from_bytes(cipher2_content, sys.byteorder) + ^ int.from_bytes(possible_key, sys.byteorder) + ).to_bytes(max(len(cipher2_content), len(possible_key)), sys.byteorder) ).decode("latin-1") ) diff --git a/hw1.1/answer.txt b/hw1.1/answer.txt new file mode 100644 index 0000000..8e2c597 --- /dev/null +++ b/hw1.1/answer.txt @@ -0,0 +1,5 @@ +1a +e--for-example--instead-of-always-being-replaced-by--say--16--will-be-replaced-by-any-one-of-the-figures-16--74--35--21--These-alternates-are-called-homophones--Sometimes-a-cipher-alphabet-will-include-symbols-that-mean-nothing-and-are-intended-to-confuse-interceptors--these-are-called-nulls--As-long-as-only-one-cipher-alphabet-is-in-use--as-above--the-system-is-called-monoalpbabetic--When--howeve + +1b +-of-Magic---II--IN-October-the-cabinet-of-Prince-Konoye-fell--and-the-Emperor-summoned-General-Hideki-Tojo-to-form-a-new-government--One-of-the-first-acts-of-the-new-Foreign-Minister--Shigenori-Togo--was-to-call-in-the-chief-of-the-cable-section--Togo--remembering-a-book-that-Herbert-O--Yardley-had-written-disclosing-his-1920-solution-of-Japanese-diplomatic-codes--asked-the-cable-chief--Kazuji-Kam \ No newline at end of file diff --git a/hw1.2/3/rsa/attackereavesdrop.pcap b/hw1.2/3/rsa/attackereavesdrop.pcap new file mode 100644 index 0000000..f3e54d8 Binary files /dev/null and b/hw1.2/3/rsa/attackereavesdrop.pcap differ diff --git a/hw1.2/3/rsa/sha512sums.txt b/hw1.2/3/rsa/sha512sums.txt new file mode 100644 index 0000000..44c7b81 --- /dev/null +++ b/hw1.2/3/rsa/sha512sums.txt @@ -0,0 +1 @@ +13922541651cb1b459187120a6b3621bdc2bfe65ebc18b7d88c9a9fadddd5dbb7073885f7fcde061fd5a3c10f7ef1b731a0c694643d18c06992e5b707c32bd0f plaintext.txt diff --git a/hw1.2/3/withkey/caesarkey.txt b/hw1.2/3/withkey/caesarkey.txt new file mode 100644 index 0000000..bab30ac --- /dev/null +++ b/hw1.2/3/withkey/caesarkey.txt @@ -0,0 +1 @@ +Key is Y i.e. rotating by 24 diff --git a/hw1.2/3/withkey/ciphertext.txt b/hw1.2/3/withkey/ciphertext.txt new file mode 100644 index 0000000..7bc639c --- /dev/null +++ b/hw1.2/3/withkey/ciphertext.txt @@ -0,0 +1 @@ +PMNMPRGMLYRCJWOSGBQKCBYJJGMLKGAFCJMZQGACZMVUCYIDGQFQASQRMKQGLBMARPGLYRCGLOSGPCPQYLARGDGCBAFYDDQCGQKMJMEWQNCPAYJCQAFGQFMJKQZPYEECPQQRSKZJCBRUCPIGLESPMJMEGQRQNPMQNCARSQCQZSLQCLNPGQQGCQRGLOSGPGLEZPYLAFCQ \ No newline at end of file diff --git a/hw1.2/3/withkey/juliakey.txt b/hw1.2/3/withkey/juliakey.txt new file mode 100644 index 0000000..c46b268 --- /dev/null +++ b/hw1.2/3/withkey/juliakey.txt @@ -0,0 +1 @@ +Key is shifting by 1 and XORing with YfiSgCbepeey diff --git a/hw1.2/3/withkey/juliaplaintext.txt.gz.enc b/hw1.2/3/withkey/juliaplaintext.txt.gz.enc new file mode 100644 index 0000000..0830476 --- /dev/null +++ b/hw1.2/3/withkey/juliaplaintext.txt.gz.enc @@ -0,0 +1,2 @@ +gqyC7=pcgEgMYR0yZKyDȍP9H7ψ15i&Fl/Z?![ +r#:x0x}ճ!L6^xJTE+K3!eRLp{RyfD#7CqQTiDdFLbrJƒ.)H< YKR}{N)΢Œ,2A7΄A"|k/֩"g|z#!dgHLٲ'x7^S&yPTcmD^Cf1DF<dS-b\,VWSkϴDOkg=/p2r?rNbA|\ym\GL]h I1~,&.4-Ϯ573a=rv0Au&O%_9VpU!nڈ,\e޷褍i4;YsQD[,p^CQ+mUeU^kIEI3AC::b׫aCb \ No newline at end of file diff --git a/hw1.2/3/withkey/sha512sums.txt b/hw1.2/3/withkey/sha512sums.txt new file mode 100644 index 0000000..a36cee0 --- /dev/null +++ b/hw1.2/3/withkey/sha512sums.txt @@ -0,0 +1,2 @@ +7e6386bb605d1709efed5b375b5d5df56d0bf782aba7c9753da71e21670d96baae89e1316be31b7bb3f9fe9a9bb1e9e04fccfb109e4d100aaf1e1a2065b08f24 juliaplaintext.txt +9505698ce39bd1eb8265d3cb0c4152f364a57cce9af4ea5b9aa4ad3a36f074a22210c58635a1cc198c436bb866bcfcb193f1a78f5be62b680ddc35c6c0072c05 plaintext.txt diff --git a/hw1.2/3/withoutkey/ciphertext.txt b/hw1.2/3/withoutkey/ciphertext.txt new file mode 100644 index 0000000..c0857b6 --- /dev/null +++ b/hw1.2/3/withoutkey/ciphertext.txt @@ -0,0 +1 @@ +HPDVZDOGVULQJVKLJKODQGVVQRRWLHVWDVFHQGVHWWHUVIODUHVWKLQNLQJVFDUSLQJVHGHUVVZHOOHGPHUFLOHVVRYHUVHQVLWLYHDGYHQWXUHUGLYDQVBSVLODQWLVMRFDVWDKHDGUHVWVGLVVHUWDWLRQVMRLVWVEXVVVHUDSXSSHWUBVEXQWHGDPSKLWKHDWUHVVWHUHRVXQMXVWLILHGCHSKBUXVVDEGLFDWLRQVKXVVHUOSDOPLVWIHUDOPDQQHUOHRQLGVGLOORQVZKHUHIRUHVIHUWLOLCHGGXFNELOOGXQQHVVFRUHVKDLUFXWERWWLFHOOLUHSHOJOLGHVIHOLFHVEUDLQVWRUPLQJVFOHPHQFBUHGRLQJPHGLFDLGVEOXQGHUEXVV \ No newline at end of file diff --git a/hw1.2/3/withoutkey/secretfile.txt.gz.enc b/hw1.2/3/withoutkey/secretfile.txt.gz.enc new file mode 100644 index 0000000..24d75be Binary files /dev/null and b/hw1.2/3/withoutkey/secretfile.txt.gz.enc differ diff --git a/hw1.2/3/withoutkey/sha512sums.txt b/hw1.2/3/withoutkey/sha512sums.txt new file mode 100644 index 0000000..ed4b806 --- /dev/null +++ b/hw1.2/3/withoutkey/sha512sums.txt @@ -0,0 +1,2 @@ +da1918d414a12e8453bf938218242cf348c3538ecb71da2a3857c431693516c6e23fb20cdfdf54a676bdf0a78bf0eb7fe928c389b97818ff79b7ec921742d4d4 plaintext.txt +356b8c38a00a53f1530aeeb4f30ac0bb64f7f66c9522ecfe10249c707766215af0695193a7673c35901e4d6e73397d04291fc5e47903f732b248dc241ed54729 secretfile.txt diff --git a/hw1.2/answer.txt b/hw1.2/answer.txt new file mode 100644 index 0000000..d537fcb --- /dev/null +++ b/hw1.2/answer.txt @@ -0,0 +1,10 @@ +a - caesar +left shift: +ROPORTIONATELYQUIDSMEDALLIONMICHELOBSICEBOXWEAKFISHSCUSTOMSINDOCTRINATEINQUIRERSANCTIFIEDCHAFFSEISMOLOGYSPERCALESCHISHOLMSBRAGGERSSTUMBLEDTWERKINGUROLOGISTSPROSPECTUSESBUNSENPRISSIESTINQUIRINGBRANCHES + +(right shift gave:) +NKLKNPEKJWPAHUMQEZOIAZWHHEKJIEYDAHKXOEYAXKTSAWGBEODOYQOPKIOEJZKYPNEJWPAEJMQENANOWJYPEBEAZYDWBBOAEOIKHKCUOLANYWHAOYDEODKHIOXNWCCANOOPQIXHAZPSANGEJCQNKHKCEOPOLNKOLAYPQOAOXQJOAJLNEOOEAOPEJMQENEJCXNWJYDAO +which is not english text, also sha512 sum doesn't match + +a - julia +mile Vinay and Joseph Gaussinthough not with the speed and ease of a typewriter keyboard. Rather it was the assimilation of encipherment into the overall communication process. Vernam created what came to be called "on-line encipherment" (because it was done directly on the open telegraph circuit) to distinguish it from the old, separate, off-line encipherment. He freed a fundamental process in cryptography from the shackles of time and error. He eliminated a human beingthe cipher clerkfrom the chain of communication. His great contribution was to bring to cryptography the automation that had benefited mankind so much in so many fields of endeavor. These values were immediately recognized, and Ver-nam's idea quickly kicked up a flurry of activity. He put it down on paper in a sketch dated December 17. A.T. & T. notified the Navy, with which it had worked closely in a communications demonstration the previous year, and on February 18, 1918, Vernam, Parker, Lyman F. Morehouse, equipment \ No newline at end of file diff --git a/hw1.2/caesar_with_key.py b/hw1.2/caesar_with_key.py new file mode 100644 index 0000000..290ec20 --- /dev/null +++ b/hw1.2/caesar_with_key.py @@ -0,0 +1,24 @@ +with open("3/withkey/caesarkey.txt", "r") as caesar_key_file, open( + "3/withkey/ciphertext.txt", "r" +) as caesar_cipher_file: + caesar_key_content = caesar_key_file.read() + caesar_cipher_content = caesar_cipher_file.read() + + key_shift = int(caesar_key_content.split()[-1]) + print("key shift", key_shift) + + caesar_plaintext_content_left_shift = "" + caesar_plaintext_content_right_shift = "" + for char in caesar_cipher_content: + caesar_plaintext_content_left_shift += chr( + (ord(char) - ord("A") - key_shift) % 26 + ord("A") + ) + caesar_plaintext_content_right_shift += chr( + (ord(char) - ord("A") + key_shift) % 26 + ord("A") + ) + + print("left shift") + print(caesar_plaintext_content_left_shift) + print() + print("right shift") + print(caesar_plaintext_content_right_shift) diff --git a/hw1.2/julia_with_key.py b/hw1.2/julia_with_key.py new file mode 100644 index 0000000..3c35459 --- /dev/null +++ b/hw1.2/julia_with_key.py @@ -0,0 +1,37 @@ +import sys +import os +from itertools import cycle +import gzip + + +def ror(n, rotations, width): + return (2**width - 1) & (n >> rotations | n << (width - rotations)) + + +def rol(n, rotations, width): + return (2**width - 1) & (n << rotations | n >> (width - rotations)) + + +with open("3/withkey/juliakey.txt", "r") as julia_key_file, open( + "3/withkey/juliaplaintext.txt.gz.enc", "rb" +) as julia_cipher_file: + julia_key_content = julia_key_file.read() + key_shift = int(julia_key_content.split()[4]) + key_xor = julia_key_content.split()[-1] + print("key shift", key_shift) + print("key xor", key_xor) + + julia_cipher_content = julia_cipher_file.read() + result = bytes() + for c_byte, k_byte in zip(julia_cipher_content, cycle(key_xor)): + tmp = c_byte ^ ord(k_byte) + # kinda misleading, question mentions that encryption rotates bits but didn't mention which direction + # imagine spending 3 hours thinking it's gzip when it turns out you rotate RIGHT + result += ror(c_byte ^ ord(k_byte), 1, 8).to_bytes(1, "big") + + # gzip - write as bytes, read with decompression + with open("test.gz", "wb") as f: + f.write(result) + with gzip.open("test.gz", "r") as gf: + print(gf.read().decode()) + os.remove("test.gz")