Skip to content

Commit a4afdc9

Browse files
committed
Day7 added
1 parent 1642895 commit a4afdc9

File tree

6 files changed

+166
-0
lines changed

6 files changed

+166
-0
lines changed

Day7/caser_cipher.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Caesar Cipher
3+
Caesar cipher uses keys, which encrypt the message differently
4+
depending on which key is used. The keys for the Caesar cipher are the
5+
integers from 1 to 26(a-z). Based On the key from 1-26, the given message is encoded ahead with the given key.
6+
7+
Sample Input:
8+
Security key: 3
9+
Message: anime
10+
11+
Sample Output:
12+
dqlph
13+
14+
Explaination: key=3, first character of message=a a+3=d(b,c,d),
15+
in the same way, n+3 = q (o,p,q)
16+
i+3 = l (j,k,l)
17+
m+3 = p (n,o,p)
18+
e+3 = h (f,g,h)
19+
"""
20+
import string
21+
22+
with open("actual_message.txt","w") as file:
23+
message = input("Enter the Best Anime you have watched:")
24+
file.write(message)
25+
file.close()
26+
27+
def security_key():
28+
while True:
29+
key = int(input("Security Key(1-26):"))
30+
if key not in range(1,27):
31+
continue
32+
return key
33+
34+
key = security_key()
35+
encrypt = open("actual_message.txt","r").read()
36+
upper_c = string.ascii_uppercase
37+
lower_c = string.ascii_lowercase
38+
39+
encode = ''
40+
for i in encrypt:
41+
if i in upper_c:
42+
encode+=upper_c[upper_c.index(i)+key-26] if upper_c.index(i)+key>25 else upper_c[upper_c.index(i)+key]
43+
elif i in lower_c:
44+
encode+=lower_c[lower_c.index(i)+key-26] if lower_c.index(i)+key>25 else lower_c[lower_c.index(i)+key]
45+
else:
46+
encode+=' '
47+
48+
with open("encrypted.txt","w") as new_file:
49+
new_file.write(encode)
50+
new_file.close()
51+
print("Success, Message Encrypted")

Day7/moorse_code.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Moorse Code: A-Z alphabets is replaced with sequence of dits(.) and dahs(-)
3+
4+
Here let us create two Python file. In one .py file store the Moorse Code. And In other .py file write a code to convert Text to Moorse Code
5+
6+
"""
7+
import string
8+
9+
alpha = string.ascii_uppercase
10+
mc=['.-','-...','-.-.','-...','.','..-.','--.','....','..','.---','-.-','.-..','--','-.','---','.--.','--.-','.-.','...','-','..-','...-','.--','-..-','-.--','--..']
11+
moorse = dict()
12+
for code in range(len(alpha)):
13+
moorse[alpha[code]]=mc[code]

Day7/moorse_code/moorse_code.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Program 4: Moorse Code
2+
3+
Here let us create two Python file. In one .py file store the Moorse Code. And In other .py file write a code to convert Text to Moorse Code
4+
5+
6+
import string
7+
8+
alpha = string.ascii_uppercase
9+
mc=['.-','-...','-.-.','-...','.','..-.','--.','....','..','.---','-.-','.-..','--','-.','---','.--.','--.-','.-.','...','-','..-','...-','.--','-..-','-.--','--..']
10+
moorse = dict()
11+
for code in range(len(alpha)):
12+
moorse[alpha[code]]=mc[code]
13+
14+
15+
text = input("Enter the Text: ").upper()
16+
with open("Before.txt","w") as file:
17+
file.write(text)
18+
file.close()
19+
20+
#double space means new letter, while single space is gap between two moose converted letter
21+
moorse_converted = ""
22+
for letter in text:
23+
if letter==" ":
24+
moorse_converted+=" "
25+
if letter in moorse:
26+
moorse_converted+=moorse[letter]+" "
27+
28+
with open("After.txt","w") as new:
29+
new.write(moorse_converted)
30+
31+
new.close()

Day7/moorse_code/text_to_moorse.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from moorse_code import moorse
2+
3+
text = input("Enter the Text: ").upper()
4+
with open("Before.txt","w") as file:
5+
file.write(text)
6+
file.close()
7+
8+
#double space means new letter, while single space is gap between two moose converted letter
9+
moorse_converted = ""
10+
for letter in text:
11+
if letter==" ":
12+
moorse_converted+=" "
13+
if letter in moorse:
14+
moorse_converted+=moorse[letter]+" "
15+
16+
with open("After.txt","w") as new:
17+
new.write(moorse_converted)
18+
19+
new.close()

Day7/remove_punctuation.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Remove Punctuation From a Sentence
3+
Read a File with Text inside it and remove punctuations from the text.
4+
5+
Sample Input: T%hi/s senten$ce, th@is diffi&^cu)()lt t*o re!a+d|
6+
Sample Output: This sentence this difficult to read
7+
8+
[Note: Save the Sample Input in some file]
9+
"""
10+
import string
11+
12+
punc = string.punctuation
13+
with open("reference.txt") as ref_file:
14+
content = ref_file.read()
15+
ref_file.close()
16+
17+
print("Before: {}".format(content))
18+
19+
proper_text = ""
20+
for word in content:
21+
if word in punc:
22+
pass
23+
else:
24+
proper_text+=word
25+
26+
print("After: {}".format(proper_text))

Day7/word_character_calculator.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Character and Word Calculator
3+
Write a program to print total words, total characters including spaces and total characters excluding characters from the reference.txt.
4+
5+
reference.txt :
6+
7+
Anime Quotes of Main Characters:
8+
Naruto: "Until I become Hokage, I can't die"
9+
Luffy: "I will become the Pirate King, I dont care if I die trying"
10+
Hinata: "Do you need a reason to win?"
11+
Gintoki: "The night is dark before dawn, But don't close your eyes"
12+
"""
13+
with open("reference.txt") as ref_file:
14+
content = ref_file.read()
15+
16+
space,without_space=0,0
17+
for word in content:
18+
if word == "\n":
19+
pass
20+
elif word == ' ':
21+
without_space+=1
22+
else:
23+
without_space+=1
24+
space+=1
25+
26+
print(" Total Words:{} \n Total Characters:{} \n Total Characters without space:{}".format(len(content.split()),without_space,space))

0 commit comments

Comments
 (0)