Skip to content

Commit

Permalink
Added decrypt and encrypt source files.
Browse files Browse the repository at this point in the history
i
  • Loading branch information
Srinibas Biswal authored and Srinibas Biswal committed Jan 9, 2017
1 parent df87511 commit 4a97942
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 0 deletions.
104 changes: 104 additions & 0 deletions decrypt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@

def alpha_reverse(list):
f_output=input("Enter the file name with extension name(.txt) in which the decrypted code will be saved: ")
coding=list[0]+list[1]+list[2]+list[3]
a_list=list[5:]
dlist=[]
if coding=='#a1#':
for i in a_list:
if ord(i)>=97 and ord(i)<=122:
d=122-ord(i)
dlist.append(chr(97+d))
elif ord(i)>=0 and ord(i)<=31 :
d=31-ord(i)
dlist.append(chr(0+d))
elif ord(i)>=32 and ord(i)<=64:
d=64-ord(i)
dlist.append(chr(32+d))
elif ord(i)>=65 and ord(i)<=90:
d=90-ord(i)
dlist.append(chr(65+d))
elif ord(i)>=91 and ord(i)<=96:
d=96-ord(i)
dlist.append(chr(91+d))
elif ord(i)>=123 and ord(i)<=126 :
d=126-ord(i)
dlist.append(chr(123+d))
elif ord(i)>=128 and ord(i)<=255 :
d=255-ord(i)
dlist.append(chr(128+d))

dll=len(dlist)
k=open(f_output, 'a')
i=0
while i<dll:
k.write(str(dlist[i]))
i=i+1
k.close()
print("Decryption Completed!!")
else:
print('Cryptography code mismatch!!')

def morse_code(f_name):
f_output=input("Enter the file name with extension name(.txt) in which the decrypted code will be saved: ")
rlist=[]
f=open(f_name, "r")
array=f.readlines()
m_array=array[1:]
e_code=array[0]
#print(e_code)

CODE = {'.-\n':'A','-...\n':'B','-.-.\n':'C','-..\n':'D','.\n':'E','..-.\n':'F','--.\n':'G','....\n':'H','..\n':'I','.---\n':'J','-.-\n':'K','.-..\n':'L','--\n':'M','-.\n':'N','---\n':'O','.--.\n':'P','--.-\n':'Q','.-.\n':'R','...\n':'S','-\n':'T','..-\n':'U','...-\n':'V','.--\n':'W','-..-\n':'X','-.--\n':'Y','--..\n':'Z','-----\n':'0','.----\n':'1','..---\n':'2','...--\n':'3','....-\n':'4','.....\n':'5','-....\n':'6','--...\n':'7','---..\n':'8','----.\n':'9','@\n':' '}
if e_code=='#m1#\n':
for i in m_array:
#print(CODE[i.upper()])
rlist.append(CODE[i.upper()])
#print(rlist)
rdl=len(rlist)
k=open(f_output,'a')
i=0
while i<rdl:
k.write(str(rlist[i]))
i=i+1
k.close()
print("Decryption Completed!!")
else:
print('Crytography code mismatch!! ')

if __name__=="__main__":

while 1:
menuch=input("Go to the menu: Y/N: ")
if menuch=="y" or menuch=='Y':
f_name=input("Enter the the file name (with extension name (.txt))in which the encrypted code is present: ")
list=[]

fp=open(f_name,'r')
while 1:
char=fp.read(1)
if not char:
break
list.append(char)
print(list)
print("\n\n")
print(" a: Alpha reverse")
print(' b: Morse Code')
print(" x : Exit")
ch = input("Enter in which format the code is: ")


if ch == 'a':
alpha_reverse(list)


if ch=='b':
morse_code(f_name)

if ch == 'x':
break

elif ch!='a' and ch!='b' and ch!='x':
print('invalid choice')

else:
break
89 changes: 89 additions & 0 deletions encrypt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@


def alpha_reverse(ulist):
f_name=input("File name with extension name(.txt) the message is to be saved : ")
rlist=['#a1#\n']
for i in ulist:
if ord(i)>=97 and ord(i)<=122 :
d=122-ord(i)
rlist.append(chr(97+d))
elif ord(i)>=0 and ord(i)<=31 :
d=31-ord(i)
rlist.append(chr(0+d))
elif ord(i)>=32 and ord(i)<=64:
d=64-ord(i)
rlist.append(chr(32+d))
elif ord(i)>=65 and ord(i)<=90:
d=90-ord(i)
rlist.append(chr(65+d))
elif ord(i)>=91 and ord(i)<=96:
d=96-ord(i)
rlist.append(chr(91+d))
elif ord(i)>=123 and ord(i)<=126 :
d=126-ord(i)
rlist.append(chr(123+d))
elif ord(i)>=128 and ord(i)<=255 :
d=255-ord(i)
rlist.append(chr(128+d))


rdl=len(rlist)
k=open(f_name, 'a')
i=0
while i<rdl:
k.write(str(rlist[i]))
i=i+1
k.close()


def morse_code(ulistm):
f_name=input("File name with extension name(.txt) the message is to be saved: ")
CODE = {'A': '.-','B': '-...','C': '-.-.','D': '-..','E': '.','F': '..-.','G': '--.','H': '....','I': '..','J': '.---','K': '-.-','L': '.-..','M': '--','N': '-.','O': '---','P': '.--.','Q': '--.-','R': '.-.','S': '...','T': '-','U': '..-','V': '...-','W': '.--','X': '-..-','Y': '-.--','Z': '--..','0': '-----','1': '.----','2': '..---','3': '...--','4': '....-','5': '.....','6': '-....','7': '--...','8': '---..','9': '----.',' ': '@'}
mlist=['#m1#']
for i in ulistm:
#print (CODE[i.upper()])
mlist.append(CODE[i.upper()])
#print(mlist)
rdl=len(mlist)
k=open(f_name, 'a')
i=0
while i<rdl:
k.write(str(mlist[i]))
k.write('\n')
i=i+1
k.close()




if __name__=="__main__":

ulist=[]
ulistm=[]

while 1:
print(" a: Alpha reverse")
print(' b: Morse Code')
print(" x : Exit")
ch = input("Enter Choice: ")


if ch == 'a':
udata=input("enter the message : ")
ulist[1:0]=udata
alpha_reverse(ulist)


if ch=='b':
udata=input("enter the message (Please use characters from A-Z or 0-9 and blank space. Special characters cannot be converted.):\n")
ulistm[1:0]=udata
morse_code(ulistm)

if ch == 'x':
print(ch)
break

elif ch!='a' and ch!='b' and ch!='x':
print('invalid choice')


0 comments on commit 4a97942

Please sign in to comment.