From 640aa3e9aff14d017cfdbab6a5958a0a394c80cc Mon Sep 17 00:00:00 2001 From: Kaushik Narayan R Date: Wed, 31 Jan 2024 15:41:22 -0700 Subject: [PATCH] 1.1 done also initial commit --- hw1.1/1a.py | 10 ++++++++++ hw1.1/1b.py | 19 +++++++++++++++++++ hw1.1/3/forstudents/a/ciphertext.bin | Bin 0 -> 400 bytes hw1.1/3/forstudents/a/key.bin | Bin 0 -> 400 bytes hw1.1/3/forstudents/b/ciphertext1.bin | Bin 0 -> 400 bytes hw1.1/3/forstudents/b/ciphertext2.bin | Bin 0 -> 400 bytes hw1.1/3/forstudents/b/plaintext1.txt | 1 + 7 files changed, 30 insertions(+) create mode 100644 hw1.1/1a.py create mode 100644 hw1.1/1b.py create mode 100644 hw1.1/3/forstudents/a/ciphertext.bin create mode 100644 hw1.1/3/forstudents/a/key.bin create mode 100644 hw1.1/3/forstudents/b/ciphertext1.bin create mode 100644 hw1.1/3/forstudents/b/ciphertext2.bin create mode 100644 hw1.1/3/forstudents/b/plaintext1.txt diff --git a/hw1.1/1a.py b/hw1.1/1a.py new file mode 100644 index 0000000..337b95b --- /dev/null +++ b/hw1.1/1a.py @@ -0,0 +1,10 @@ +with open("3/forstudents/a/ciphertext.bin", "rb") as cipher_file, open( + "3/forstudents/a/key.bin", "rb" +) as key_file: + cipher_content = cipher_file.read() + 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() + ) diff --git a/hw1.1/1b.py b/hw1.1/1b.py new file mode 100644 index 0000000..4362881 --- /dev/null +++ b/hw1.1/1b.py @@ -0,0 +1,19 @@ +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: + cipher1_content = cipher1_file.read() + cipher2_content = cipher2_file.read() + 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") + print( + ( + ( + int.from_bytes(cipher2_content, "big") + ^ int.from_bytes(possible_key, "big") + ).to_bytes(max(len(cipher2_content), len(possible_key)), "big") + ).decode("latin-1") + ) diff --git a/hw1.1/3/forstudents/a/ciphertext.bin b/hw1.1/3/forstudents/a/ciphertext.bin new file mode 100644 index 0000000000000000000000000000000000000000..9437c337e85460554cfb28a1ada3b4c607a99d00 GIT binary patch literal 400 zcmV;B0dM{&RoU~rXJo$nuqZsd>EgDljFF6;r&ob0OIW|Z;_eV(CZRhv^<2j6*aiu| zdg8csFqWuk{6xsdvdudR6=g~>cNzjo zM~lxFhdYl1kKEde*4Brkly*^krR3U78`XMKQ*66dBXP}{pZwJD`oBHsW2Nkx&r|MO za50rly-MMe3ZFHE?e4t)w)}zSte7((()^e8sVDJEpQ%mAw}DfK5yz0H+r1;57-;S@ z%6W=3fG5>RsAZ?01eM9|xU4dh*(#{4Jq0FE>JC=pZv_Pef)^W7YJeNuM1x^r>u?~Y u{pXofCMs_-W6y3&UPtn>*{Cy>?~Z z8He0hQtyRCk0r6{pZpCcI1(dW8#iDD4;eNnEk@>G9fh|A;0S5Z>8@9Ql_WR9u6rQ* zF{?R?5i{~E`zWcV*sR1*(LXmWJJju`?|GFL5sNVM(d2vtqdqtx2@fs_0HI8K&-uHN z9~NFtqF$Z#-};?8q}85-Ue%{dZY5GO*f}GFNn~3Ry-~ApzpqaXs$V;6r`-CIC+wCB#Jci?nx6)1eH3^*_ zr5EN+tw_5qg$B;=Z1B6o*}y{kxJb>|5NuU_gJ64>9AGFZ<77572=8sVX|5Fsj$KpS uj+6X33qu?q0Iul@rsl>k?b9;Z#xE3fd1>T#Y-VezFP2i%dbvbO3*|9B=*wIH literal 0 HcmV?d00001 diff --git a/hw1.1/3/forstudents/b/ciphertext1.bin b/hw1.1/3/forstudents/b/ciphertext1.bin new file mode 100644 index 0000000000000000000000000000000000000000..22f6bbd2877cab04f3053dd106f729ada06deb00 GIT binary patch literal 400 zcmV;B0dM|Oiw=WwV$jQFvBikzMk#k-Bz$1UX9(+i%|n&|h>CS;Q2&~2Vd9SLzBn7m zX87$ow2QzWrL0*1o=RUw#V6pyC|A=k`KVNm0V?AXd=g_lN6^tH4d z5K8uk66so1OCFL%d`$Zzy_6y4WW-nj z_WZZ}Q9_KO@^Ue(bW(RDi>&%6q@mr{4~wZAFPCp&`vxeB_D4I$x)nb@?qcSCl9mVg z0VyGSDOut^T}a6L2)xFL5HZ2U;#beJRCtUpx`zOPh`PRTApQg$KkYspLObL6dr>1r zx(B=A`t~qC&rYoSMxQKIFc(BI35nL*3VU$6r^UpPl)bn2f7_>ti0E@p7$7*`_NnR} z16=5b3#JkZRv4TcFbwuHP8^?|CpsgtGY73!LSR@xo#U^eyN>LnLI6m|o%YIcgN2LV z&#&~hogTI6unh@zyPUJI{JVzV!PA=f#v~%h{Iy1uDDHQn*>&v6`d)_g^HMgMHqn+A u3Q^bqf--Hz2i6inI(A8rw*f!w-iX=@lcwcv4#!8GGwLfkN`1Icf}JS^6vmwZ literal 0 HcmV?d00001 diff --git a/hw1.1/3/forstudents/b/plaintext1.txt b/hw1.1/3/forstudents/b/plaintext1.txt new file mode 100644 index 0000000..8307de3 --- /dev/null +++ b/hw1.1/3/forstudents/b/plaintext1.txt @@ -0,0 +1 @@ +-out-the-important-messages-ever-more-surely--Bratton-and-Kramer-hustled-from-place-to-place-with-their-locked-briefcases--MAGIC-gushed-forth-in-profusion--So-effectively-did-the-cryptanalytic-agencies-perform-that-Marshall-could-say-of-this--priceless-asset---this-most-complete-and-up-to-the-minute-intelligence-that-any-nation-had-ever-had-concerning-a-probable-enemy--this-necromantic-gift-of-the \ No newline at end of file