diff --git a/rad-be-damned/chall.yaml b/rad-be-damned/chall.yaml index 6432b04..579b9c1 100644 --- a/rad-be-damned/chall.yaml +++ b/rad-be-damned/chall.yaml @@ -1,22 +1,17 @@ name: rad-be-damned categories: - crypto -value: 100 +value: 125 flag: file: ./flag.txt description: | My friend seems to be communicating something but I can't make out anything. Why do we live so close to Chernobyl anyways? - - (Each letter is encoded with CRC-4-ITU) hints: - - What can CRCs also do besides error detection? + - Encoded with CRC (Cyclic Redundancy Checks) files: - - src: ./flag_gen.py -deploy: - nc: - build: . - expose: 1337/tcp + - src: ./message.py + - src: ./output.txt authors: - Nikhil visible: true diff --git a/rad-be-damned/error_pattern.txt b/rad-be-damned/error_pattern.txt deleted file mode 100644 index 9b13e99..0000000 --- a/rad-be-damned/error_pattern.txt +++ /dev/null @@ -1 +0,0 @@ -fjfcdkgcgfdhgjhikdelfekaaeacabdkagacleegblbgdcbcgdfeehdaialfajhkafle \ No newline at end of file diff --git a/rad-be-damned/flag_gen.py b/rad-be-damned/flag_gen.py deleted file mode 100644 index 3807cbb..0000000 --- a/rad-be-damned/flag_gen.py +++ /dev/null @@ -1,40 +0,0 @@ -def find_leftmost_set_bit(plaintext): - pos = 0 - while plaintext > 0: - plaintext = plaintext >> 1 - pos += 1 - return pos - -def crc_encrypt(plaintext: str): - crc_plaintext = "" - for letter in plaintext: - crc_poly = int("10011", 2) - crc_poly_length = crc_poly.bit_length() - bin_letter, crc_rem = ord(letter), ord(letter) * 2**(crc_poly_length - 1) - while (crc_rem.bit_length() >= crc_poly_length): - first_pos = find_leftmost_set_bit(crc_rem) - crc_rem = crc_rem ^ (crc_poly << (first_pos - crc_poly_length)) - let_crc = format(bin_letter, "08b") + format(crc_rem, "0" + f"{crc_poly_length - 1}" + "b") - crc_plaintext += let_crc - return crc_plaintext - -def expose_to_radiation(text: str): - corrupted_str = "" - with open("error_pattern.txt") as f: - for ind in range(0, len(text), 12): - let = f.read(1) #between a and l inclusive - if let != "": - bit_mask = 2 ** (ord(let) - 97) - rad_let = int(text[ind:ind+12], base=2) ^ bit_mask - corrupted_str += format(rad_let, "012b") - return corrupted_str - -def main(): - with open('flag.txt') as f: - plaintext = f.read().strip() - crc_plaintext = crc_encrypt(plaintext) - cor_text = expose_to_radiation(crc_plaintext) - print(f"Here's flag: {cor_text}") - -if __name__ == '__main__': - main() \ No newline at end of file diff --git a/rad-be-damned/message.py b/rad-be-damned/message.py new file mode 100644 index 0000000..baa098b --- /dev/null +++ b/rad-be-damned/message.py @@ -0,0 +1,40 @@ +import random +def find_leftmost_set_bit(plaintext): + pos = 0 + while plaintext > 0: + plaintext = plaintext >> 1 + pos += 1 + return pos + +def encrypt(plaintext: str): + enc_plaintext = "" + + for letter in plaintext: + cp = int("10011", 2) + cp_length = cp.bit_length() + bin_letter, rem = ord(letter), ord(letter) * 2**(cp_length - 1) + while (rem.bit_length() >= cp_length): + first_pos = find_leftmost_set_bit(rem) + rem = rem ^ (cp << (first_pos - cp_length)) + enc_plaintext += format(bin_letter, "08b") + format(rem, "0" + f"{cp_length - 1}" + "b") + + return enc_plaintext + +def rad(text: str): + corrupted_str = "" + for ind in range(0, len(text), 12): + bit_mask = 2 ** (random.randint(0, 11)) + snippet = int(text[ind : ind + 12], base = 2) + rad_str = snippet ^ bit_mask + corrupted_str += format(rad_str, "012b") + return corrupted_str + +def main(): + with open('flag.txt') as f: + plaintext = f.read().strip() + enc_plaintext = encrypt(plaintext) + cor_text = rad(enc_plaintext) + print(cor_text) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/rad-be-damned/output.txt b/rad-be-damned/output.txt new file mode 100644 index 0000000..64ec345 --- /dev/null +++ b/rad-be-damned/output.txt @@ -0,0 +1 @@ +011000001011010000111000011000111110011000111100011101001100001001100111011111110110011110010100011100010111011011111001010011011011010100011010001010011110010110010000001110111010001000011100011100011100010011111101010101101011110000110010001101100011011010100011001001010010001011011111011110000010001101100110010000110011011101110101010010111000011100011001010100011001001000111000001101010001011000100111010011000001011100011111111101010111010001001000001101000000001101011100010101101010101011011110011010100010010010010011010101010101010000010000001011011100011000011010010000111110001110011111011100011101010110001010010100100111001110011100011010101000011000101010001000101001001100011101111101100010010011100000010101111010011101101000011100100101001001000001010001111111010001001101111110100101011111001100 \ No newline at end of file