Friday, 6 September 2013

Python Program - Replace characters into 4 symbols

Python Program - Replace characters into 4 symbols

I'm making a simple cipher program which replaces alphabetical characters
into symbols and extended ASCII characters.
Right now, it enciphers a single character onto a single symbol. However,
for more variety, i want it to become into 4 symbol code.
for Example:
Normal = a = $
Advanced = a = %"££
Could anyone suggest something?
import sys,os
directory = input("Directory : ")
try:
with open(get_dir): pass
except IOError:
print("ERROR - File not found")
time.sleep(2)
sys.exit("Closing..")
if get_dir.endswith('.txt'):
print(".txt extension")
elif get_dir.endswith('.py'):
print(".py extension")
else:
print("Invalid extension!")
f1 = open(directory, 'r')
f2 = open(directory+'.encrypted', 'w')
for line in f1:
line = line.replace('a', '$').replace('b', '£').replace('c',
'=').replace('d', '¬')
f2.write(line)
f1.close()
f2.close()
os.remove(directory)

No comments:

Post a Comment