elbarto_87
October 2nd, 2008, 12:10 PM
Hi all,
I have created 2 simple programs in IDLE. "encrypt" moves the characters of a string by a certain specified amount and "aencrypt" lists all the possiblites that a string could represent.
I have saved the 2 files in the default idle directory. When I start idle, I have to open each script run the module before I can call the functions from the interpreter. I was just wondering if there was an easier way to do this? Obviously it is no big deal since I am only dealing with 2 functions in this instance, but If I have a library of scripts it would be convenient to import all the scripts so all the commands were available.
I have included my 2 scripts just for kicks. Im sure you could do this in less lines as I have seen in the python challenge but im still learning the python syntax and think this is a good exercise to learn with.
Thanks
Elbarto
def encrypt(string=0,num_shift=0):
if string == 0 and num_shift == 0:
string = raw_input("Enter the string to shift:")
num_shift = int(raw_input("Enter phase shift [pos or neg] :"))
new_word = ""
for x in string:
if ord(x)>=65 and ord(x)<=90:
new_ord = (ord(x)+num_shift)
if new_ord > 90:
new_ord = new_ord - 26
elif new_ord < 65:
new_ord = new_ord + 26
elif ord(x)>=97 and ord(x)<=122:
new_ord = (ord(x)+num_shift)
if new_ord > 122:
new_ord = new_ord - 26
elif new_ord < 97:
new_ord = new_ord + 26
else:
new_ord = ord(x)
new_word = new_word + chr(new_ord)
print(new_word)
def aencrypt(string=0):
if string == 0:
string = raw_input("Enter the string to interate solution:")
for i in range(1,27):
new_word = ""
for x in string:
if ord(x)>=65 and ord(x)<=90:#in capital range
new_ord = (ord(x)+i)
if new_ord > 90:
new_ord = new_ord - 26
elif new_ord < 65:
new_ord = new_ord + 26
elif ord(x)>=97 and ord(x)<=122:#in lower case region
new_ord = (ord(x)+i)
if new_ord > 122:
new_ord = new_ord - 26
elif new_ord < 97:
new_ord = new_ord + 26
else:
new_ord = ord(x)
new_word = new_word + chr(new_ord)
print new_word, "{Letter Shift Required = ", i, " or ", i - 26, "}"
I have created 2 simple programs in IDLE. "encrypt" moves the characters of a string by a certain specified amount and "aencrypt" lists all the possiblites that a string could represent.
I have saved the 2 files in the default idle directory. When I start idle, I have to open each script run the module before I can call the functions from the interpreter. I was just wondering if there was an easier way to do this? Obviously it is no big deal since I am only dealing with 2 functions in this instance, but If I have a library of scripts it would be convenient to import all the scripts so all the commands were available.
I have included my 2 scripts just for kicks. Im sure you could do this in less lines as I have seen in the python challenge but im still learning the python syntax and think this is a good exercise to learn with.
Thanks
Elbarto
def encrypt(string=0,num_shift=0):
if string == 0 and num_shift == 0:
string = raw_input("Enter the string to shift:")
num_shift = int(raw_input("Enter phase shift [pos or neg] :"))
new_word = ""
for x in string:
if ord(x)>=65 and ord(x)<=90:
new_ord = (ord(x)+num_shift)
if new_ord > 90:
new_ord = new_ord - 26
elif new_ord < 65:
new_ord = new_ord + 26
elif ord(x)>=97 and ord(x)<=122:
new_ord = (ord(x)+num_shift)
if new_ord > 122:
new_ord = new_ord - 26
elif new_ord < 97:
new_ord = new_ord + 26
else:
new_ord = ord(x)
new_word = new_word + chr(new_ord)
print(new_word)
def aencrypt(string=0):
if string == 0:
string = raw_input("Enter the string to interate solution:")
for i in range(1,27):
new_word = ""
for x in string:
if ord(x)>=65 and ord(x)<=90:#in capital range
new_ord = (ord(x)+i)
if new_ord > 90:
new_ord = new_ord - 26
elif new_ord < 65:
new_ord = new_ord + 26
elif ord(x)>=97 and ord(x)<=122:#in lower case region
new_ord = (ord(x)+i)
if new_ord > 122:
new_ord = new_ord - 26
elif new_ord < 97:
new_ord = new_ord + 26
else:
new_ord = ord(x)
new_word = new_word + chr(new_ord)
print new_word, "{Letter Shift Required = ", i, " or ", i - 26, "}"