mirror of
https://github.com/20kaushik02/CSE548_ACNS_Work.git
synced 2025-12-06 05:24:07 +00:00
1.2 part a (with key) done
This commit is contained in:
parent
640aa3e9af
commit
6ff8e3d880
@ -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()
|
||||
)
|
||||
|
||||
14
hw1.1/1b.py
14
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")
|
||||
)
|
||||
|
||||
5
hw1.1/answer.txt
Normal file
5
hw1.1/answer.txt
Normal file
@ -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
|
||||
BIN
hw1.2/3/rsa/attackereavesdrop.pcap
Normal file
BIN
hw1.2/3/rsa/attackereavesdrop.pcap
Normal file
Binary file not shown.
1
hw1.2/3/rsa/sha512sums.txt
Normal file
1
hw1.2/3/rsa/sha512sums.txt
Normal file
@ -0,0 +1 @@
|
||||
13922541651cb1b459187120a6b3621bdc2bfe65ebc18b7d88c9a9fadddd5dbb7073885f7fcde061fd5a3c10f7ef1b731a0c694643d18c06992e5b707c32bd0f plaintext.txt
|
||||
1
hw1.2/3/withkey/caesarkey.txt
Normal file
1
hw1.2/3/withkey/caesarkey.txt
Normal file
@ -0,0 +1 @@
|
||||
Key is Y i.e. rotating by 24
|
||||
1
hw1.2/3/withkey/ciphertext.txt
Normal file
1
hw1.2/3/withkey/ciphertext.txt
Normal file
@ -0,0 +1 @@
|
||||
PMNMPRGMLYRCJWOSGBQKCBYJJGMLKGAFCJMZQGACZMVUCYIDGQFQASQRMKQGLBMARPGLYRCGLOSGPCPQYLARGDGCBAFYDDQCGQKMJMEWQNCPAYJCQAFGQFMJKQZPYEECPQQRSKZJCBRUCPIGLESPMJMEGQRQNPMQNCARSQCQZSLQCLNPGQQGCQRGLOSGPGLEZPYLAFCQ
|
||||
1
hw1.2/3/withkey/juliakey.txt
Normal file
1
hw1.2/3/withkey/juliakey.txt
Normal file
@ -0,0 +1 @@
|
||||
Key is shifting by 1 and XORing with YfiSgCbepeey
|
||||
2
hw1.2/3/withkey/juliaplaintext.txt.gz.enc
Normal file
2
hw1.2/3/withkey/juliaplaintext.txt.gz.enc
Normal file
@ -0,0 +1,2 @@
|
||||
gqyC7=ðÛpc±“<C2B1>´«³¿<C2B3>°¹˜¯•‘Ž™»g‰EÓgMYR™ý0yÿ¢²ZÌ÷ÛÊKyDÈ<44>P9©HáÓý7ý´µâð¸Ïˆ¸ð1ÜÏ5i&Fl–/ÏZ?!çý[
|
||||
r#:Îx¬ñÀ0“xíÊ}Õ³!LçÐÎÙËä6é^ÖxJÂø€TEŸ+ô»ÁK3!eRåüL¹<4C>çápÎ{è‚R÷ËyfÁD#¹‘²¦Öâ7C‚qðQÀT£iDš¨ñdFÌLb…r”ˆJƒø.)º’ÉÇH<ö
YK–ÌÊÉRÐ}{N§)Ñú΢¦ÙÝÂŒ,ˆç2„ŠA7΄÷AšÃ"ê|Çk‰/<2F>Ö©"Ýg|òzù#«»×!õdgÐHL×Ù²íŒ'x7^ËóÖSºü&yPTåcmþ<6D>D^Cf1†°ØDáFª<Œ®ÈdSð-bÎ\ž,¤‘½¢VW’S—<53>âkôÖõ€ÐÜÏ´©<>ÅD°ÜOºßkgó=ÔÜÀƒ‹/ëp©2¤rÝÈô?rýNöb¦ÓA|ñÆ\éy÷®ŸüÙmî\G¦L²„]°Æh¯
I1~,•&“ï¼òþ.4-°Ï®573Ša—=”rv0Auˆ&Ož%ŒÛ_à›9V¡žŒúpìUÉÇ!ØnšÚˆ,\„eÞ·è¤<C3A8>i¯4;ìYßsQû»D¿[,¬ù¼p^<5E>CÝÝQˆ+ ÇmÈUeÛU‚¤ùœ¸^¦åÆkÜI ”E›I´³Úí3ãïAC¯È::b׫‚aCb
|
||||
2
hw1.2/3/withkey/sha512sums.txt
Normal file
2
hw1.2/3/withkey/sha512sums.txt
Normal file
@ -0,0 +1,2 @@
|
||||
7e6386bb605d1709efed5b375b5d5df56d0bf782aba7c9753da71e21670d96baae89e1316be31b7bb3f9fe9a9bb1e9e04fccfb109e4d100aaf1e1a2065b08f24 juliaplaintext.txt
|
||||
9505698ce39bd1eb8265d3cb0c4152f364a57cce9af4ea5b9aa4ad3a36f074a22210c58635a1cc198c436bb866bcfcb193f1a78f5be62b680ddc35c6c0072c05 plaintext.txt
|
||||
1
hw1.2/3/withoutkey/ciphertext.txt
Normal file
1
hw1.2/3/withoutkey/ciphertext.txt
Normal file
@ -0,0 +1 @@
|
||||
HPDVZDOGVULQJVKLJKODQGVVQRRWLHVWDVFHQGVHWWHUVIODUHVWKLQNLQJVFDUSLQJVHGHUVVZHOOHGPHUFLOHVVRYHUVHQVLWLYHDGYHQWXUHUGLYDQVBSVLODQWLVMRFDVWDKHDGUHVWVGLVVHUWDWLRQVMRLVWVEXVVVHUDSXSSHWUBVEXQWHGDPSKLWKHDWUHVVWHUHRVXQMXVWLILHGCHSKBUXVVDEGLFDWLRQVKXVVHUOSDOPLVWIHUDOPDQQHUOHRQLGVGLOORQVZKHUHIRUHVIHUWLOLCHGGXFNELOOGXQQHVVFRUHVKDLUFXWERWWLFHOOLUHSHOJOLGHVIHOLFHVEUDLQVWRUPLQJVFOHPHQFBUHGRLQJPHGLFDLGVEOXQGHUEXVV
|
||||
BIN
hw1.2/3/withoutkey/secretfile.txt.gz.enc
Normal file
BIN
hw1.2/3/withoutkey/secretfile.txt.gz.enc
Normal file
Binary file not shown.
2
hw1.2/3/withoutkey/sha512sums.txt
Normal file
2
hw1.2/3/withoutkey/sha512sums.txt
Normal file
@ -0,0 +1,2 @@
|
||||
da1918d414a12e8453bf938218242cf348c3538ecb71da2a3857c431693516c6e23fb20cdfdf54a676bdf0a78bf0eb7fe928c389b97818ff79b7ec921742d4d4 plaintext.txt
|
||||
356b8c38a00a53f1530aeeb4f30ac0bb64f7f66c9522ecfe10249c707766215af0695193a7673c35901e4d6e73397d04291fc5e47903f732b248dc241ed54729 secretfile.txt
|
||||
10
hw1.2/answer.txt
Normal file
10
hw1.2/answer.txt
Normal file
@ -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
|
||||
24
hw1.2/caesar_with_key.py
Normal file
24
hw1.2/caesar_with_key.py
Normal file
@ -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)
|
||||
37
hw1.2/julia_with_key.py
Normal file
37
hw1.2/julia_with_key.py
Normal file
@ -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")
|
||||
Loading…
x
Reference in New Issue
Block a user