Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Now outputs output.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
SnippetCat committed Jun 4, 2024
1 parent 72da79e commit 0be38d1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 50 deletions.
13 changes: 4 additions & 9 deletions rad-be-damned/chall.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion rad-be-damned/error_pattern.txt

This file was deleted.

40 changes: 0 additions & 40 deletions rad-be-damned/flag_gen.py

This file was deleted.

40 changes: 40 additions & 0 deletions rad-be-damned/message.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions rad-be-damned/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
011000001011010000111000011000111110011000111100011101001100001001100111011111110110011110010100011100010111011011111001010011011011010100011010001010011110010110010000001110111010001000011100011100011100010011111101010101101011110000110010001101100011011010100011001001010010001011011111011110000010001101100110010000110011011101110101010010111000011100011001010100011001001000111000001101010001011000100111010011000001011100011111111101010111010001001000001101000000001101011100010101101010101011011110011010100010010010010011010101010101010000010000001011011100011000011010010000111110001110011111011100011101010110001010010100100111001110011100011010101000011000101010001000101001001100011101111101100010010011100000010101111010011101101000011100100101001001000001010001111111010001001101111110100101011111001100

0 comments on commit 0be38d1

Please sign in to comment.