Skip to content

Commit

Permalink
xome crypto challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
harshit-jain52 committed Jan 9, 2025
1 parent 2c4da29 commit 1739111
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
20 changes: 20 additions & 0 deletions CTFLearn/Cryptography/120.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# [RSA Noob](https://ctflearn.com/challenge/120)

```text
e: 1
c: 9327565722767258308650643213344542404592011161659991421
n: 245841236512478852752909734912575581815967630033049838269083
```

**RSA** Intro [here](https://ctf101.org/cryptography/what-is-rsa/)

```text
c = (m^e)%n
e = 1 -> c = m%n -> m = k*n + c, where k>=0 is an integer
```

Starting from k=0, try to check which m gives a flag-like output. Luckily, here m = c works.

```bash
echo "obase=16; ibase=10; 9327565722767258308650643213344542404592011161659991421" | bc | xxd -r -p
```
27 changes: 27 additions & 0 deletions CTFLearn/Cryptography/121.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# [So many 64s](https://ctflearn.com/challenge/121)

Repeatedly decode (b64) until the string is of small length, say 30
Bash script:

```bash
if [ $# -eq 0 ]; then
echo "Usage: $0 <input_file>"
exit 1
fi

if [ ! -f "$1" ]; then
echo "Error: File '$1' does not exist."
exit 2
fi

input_text=$(cat "$1")

while [ ${#input_text} -gt 30 ]; do
input_text=$(echo "$input_text" | base64 -d)

if [ $? -ne 0 ]; then
echo "$input_text"
exit 3
fi
done
```
33 changes: 33 additions & 0 deletions CTFLearn/Cryptography/238.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# [Substitution Cipher](https://ctflearn.com/challenge/238)

Python script:

```python
# Mapping defined by pure observation, intuition, manual substitution and repeated runs of code
REVERSE_CIPHER_ALPHABET = {
'M': 'T', 'I': 'H', 'T': 'E', 'L': 'S', 'O': 'I', 'F': 'N', 'S':'L', 'B':'Y', 'K': 'R', 'W': 'U', 'Z': 'B', 'R':'D', 'E':'C', 'D': 'M', 'X': 'V', 'G':'O', 'C': 'W', 'U':'G', 'Q':'K','Y':'F', 'H':'P'
}

def decode_substitution_cipher(cipher_text):
decoded_message = ''.join(
REVERSE_CIPHER_ALPHABET.get(char, char) for char in cipher_text.upper()
)
return decoded_message

def read_cipher_text(file_path):
try:
with open(file_path, 'r', encoding='utf-8') as file:
return file.read()
except FileNotFoundError:
print(f"Error: File '{file_path}' not found.")
return ""

if __name__ == "__main__":
file_path = "Substitution.txt"
cipher_text = read_cipher_text(file_path)

if cipher_text:
decoded_message = decode_substitution_cipher(cipher_text)
print("Decoded Message:")
print(decoded_message)
```
22 changes: 22 additions & 0 deletions CTFLearn/Cryptography/263.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# [5x5 Crypto](https://ctflearn.com/challenge/263)

Python script:

```python
grid5x5 = [
['a','b','c','d','e'],
['f','g','h','i','j'],
['l','m','n','o','p'],
['q','r','s','t','u'],
['v','w','x','y','z']
]

text="1-3,4-4,2-1,{,4-4,2-3,4-5,3-2,1-2,4-3,_,4-5,3-5,}"
text = text.split(',')
for t in text:
if '-' in t:
x,y = t.split('-')
print(grid5x5[int(x)-1][int(y)-1],end='')
else:
print(t,end='')
```
21 changes: 21 additions & 0 deletions CTFLearn/Cryptography/443.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# [HyperStream Test #2](https://ctflearn.com/challenge/443)

Use **Bacon Cipher** (original 24-letter variant):

```python
BACON_CIPHER_DICT = {
'AAAAA': 'A', 'AAAAB': 'B', 'AAABA': 'C', 'AAABB': 'D', 'AABAA': 'E',
'AABAB': 'F', 'AABBA': 'G', 'AABBB': 'H', 'ABAAA': 'I', 'ABAAB': 'K',
'ABABA': 'L', 'ABABB': 'M', 'ABBAA': 'N', 'ABBAB': 'O', 'ABBBA': 'P',
'ABBBB': 'Q', 'BAAAA': 'R', 'BAAAB': 'S', 'BAABA': 'T', 'BAABB': 'U',
'BABAA': 'W', 'BABAB': 'X', 'BABBA': 'Y', 'BABBB': 'Z'
}

def decode_bacon(bacon_input):
bacon_groups = [bacon_input[i:i+5] for i in range(0, len(bacon_input), 5)]
decoded_message = ''.join(BACON_CIPHER_DICT.get(group, '') for group in bacon_groups)
return decoded_message

decoded_flag = decode_bacon(bacon_input)
print(decoded_flag.lower())
```

0 comments on commit 1739111

Please sign in to comment.