Skip to content

Commit d5fa0f5

Browse files
Merge pull request #1680 from Harshit28j/cypher_buster_by_hj
Adding cypher buster script
2 parents f500bf3 + c2cddf7 commit d5fa0f5

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

cipher_buster/cipher_buster.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import math
2+
import sys
3+
# Caesar Cipher decryption function
4+
def caesar_decrypt(ciphertext, shift):
5+
plaintext = ""
6+
for char in ciphertext:
7+
if char.isalpha():
8+
ascii_offset = 65 if char.isupper() else 97
9+
decrypted_char = chr((ord(char) - shift - ascii_offset) % 26 + ascii_offset)
10+
plaintext += decrypted_char
11+
else:
12+
plaintext += char
13+
return plaintext
14+
15+
# Transposition Cipher decryption function
16+
def trans_decrypt(en_msg, k):
17+
message = en_msg
18+
key = k
19+
numOfColumns = int(math.ceil(len(message) / float(key)))
20+
numOfRows = k
21+
numOfShadedBoxes = (numOfColumns * numOfRows) - len(message)
22+
plaintext = [''] * numOfColumns
23+
column = 0
24+
row = 0
25+
for symbol in message:
26+
plaintext[column] += symbol
27+
column += 1 # Point to the next column.
28+
if (column == numOfColumns) or (column == numOfColumns - 1 and row >= numOfRows - numOfShadedBoxes):
29+
column = 0
30+
row += 1
31+
return ''.join(plaintext)
32+
33+
# Main program
34+
def main():
35+
don_know = "[If you don't know the shift/key just press enter; the script will try all possible combinations then]"
36+
print("Welcome to the Encryption Decryption Program!")
37+
38+
# Prompt user for encryption method
39+
try:
40+
method = int(input("Which encryption method would you like to decrypt?\nChoose number\n1) Caesar\n2) Transposition\n>"))
41+
except ValueError:
42+
print("Invalid selection")
43+
sys.exit()
44+
45+
# Prompt user for ciphertext
46+
ciphertext = input("Enter the ciphertext to decrypt: ")
47+
48+
# Decrypt based on chosen method
49+
if method == 1 and len(ciphertext)!=0:
50+
shift = input(f"Enter the shift value used in the Caesar cipher:\n{don_know}\n>")
51+
52+
if shift == '':
53+
for i in range(1, 26):
54+
plaintext = caesar_decrypt(ciphertext, i)
55+
print(plaintext)
56+
57+
elif shift.isnumeric():
58+
shift = int(shift)
59+
plaintext = caesar_decrypt(ciphertext, shift)
60+
print(plaintext)
61+
62+
else:
63+
print('Invalid Command')
64+
65+
elif method == 2 and len(ciphertext)!=0:
66+
key = input(f"Enter the key used in the transposition cipher:\n{don_know}\n>")
67+
if key == '':
68+
for i in range(1, 26):
69+
plaintext = trans_decrypt(ciphertext, i)
70+
print(plaintext)
71+
72+
elif key.isnumeric():
73+
key = int(key)
74+
plaintext = trans_decrypt(ciphertext, key)
75+
print(plaintext)
76+
77+
else:
78+
print('Invalid Command')
79+
80+
else:
81+
print("Invalid encryption method specified or No cipher text is given")
82+
83+
# Run the program
84+
if __name__ == "__main__":
85+
main()

cipher_buster/readme.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Cipher Buster: Brute Force Decryption for Caesar and Transposition Ciphers
2+
3+
Cipher Buster is a Python script that performs a brute force attack on Caesar Cipher and Transposition Cipher encryption. It allows you to analyze the security of these encryption methods by attempting to crack them through an exhaustive search of all possible keys.
4+
5+
## Features
6+
7+
- Decrypt ciphertext encrypted using the Caesar Cipher.
8+
- Decrypt ciphertext encrypted using the Transposition Cipher.
9+
- Perform automatic brute force decryption by trying all possible shift values for Caesar Cipher or key values for Transposition Cipher.
10+
- User-friendly command-line interface for input and interaction.
11+
12+
## Usage
13+
14+
1. Make sure you have Python 3.x installed on your system.
15+
2. Clone this repository or download the `cipher_buster.py` file.
16+
3. Open a terminal or command prompt and navigate to the directory where the script is located.
17+
4. Run the script using the following command: python cipher_buster.py
18+
5. Follow the prompts to select the encryption method (Caesar or Transposition) and provide the ciphertext.
19+
6. If you know the shift value or key, enter it when prompted. Otherwise, leave it blank to try all possible combinations.
20+
7. The script will display the decrypted plaintext for each potential key or shift value.
21+
22+
## Examples
23+
24+
### Decrypting Caesar Cipher
25+
26+
Which encryption method would you like to decrypt?
27+
Choose number:
28+
1) Caesar
29+
2) Transposition
30+
> 1
31+
32+
Enter the ciphertext to decrypt: VQREQFGT
33+
34+
Enter the shift value used in the Caesar cipher:
35+
[If you don't know the shift/key, just press enter; the script will try all possible combinations then]
36+
> 2
37+
38+
TOPSECRET
39+
40+
## Decrypting Transposition Cipher
41+
42+
Which encryption method would you like to decrypt?
43+
Choose number:
44+
1) Caesar
45+
2) Transposition
46+
> 2
47+
48+
Enter the ciphertext to decrypt: AEIMNORTUAYOBCEFHLPET
49+
50+
Enter the key used in the transposition cipher:
51+
[If you don't know the shift/key, just press enter; the script will try all possible combinations then]
52+
>
53+
54+
IMAHIDDENMESSAGEFORYOU

0 commit comments

Comments
 (0)