From 54a15bfc54867408e3124c3de4097288999c635c Mon Sep 17 00:00:00 2001 From: rahulkumaran Date: Wed, 6 Dec 2017 13:06:06 +0530 Subject: [PATCH 1/5] Code for Caesarcipher in Python --- .../RSA Algortihm/Caesarcipher.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Security Algorithms/Cryptography/RSA Algortihm/Caesarcipher.py diff --git a/Security Algorithms/Cryptography/RSA Algortihm/Caesarcipher.py b/Security Algorithms/Cryptography/RSA Algortihm/Caesarcipher.py new file mode 100644 index 000000000..6eeb5260e --- /dev/null +++ b/Security Algorithms/Cryptography/RSA Algortihm/Caesarcipher.py @@ -0,0 +1,34 @@ +""" +A Caesar Cipher function for both, encryption and decryption. +After giving the string that you want, encryption will take place by shifting +characters to the right and the decrypted string can be obtained by shifting +the encrypted string to the left. +The cipher is ready for Capital Letters only +""" + +def encrypt(message,key): + ascii_vals_enc=[ord(c) for c in message] #To get a list of ASCII Values of each character in string + for i in range(0,len(ascii_vals_enc)): + if(ascii_vals_enc[i]>=65 and ascii_vals_enc[i]<=90): + ascii_vals_enc[i] = 65 + (ascii_vals_enc[i] + key - 91)%26 #If the values in the list are greater than 65 and 90, we get it back b/w 65 and 90 + encrypt_string = ''.join(chr(i) for i in ascii_vals_enc) # To get the encrypted string using the list of manipulated ASCII vals + return encrypt_string + +def decrypt(message,key): + ascii_vals_dec=[ord(c) for c in message] + for i in range(0,len(ascii_vals_dec)): + if(ascii_vals_dec[i]>=65 and ascii_vals_dec[i]<=90): + ascii_vals_dec[i] = 90 - (90 - ascii_vals_dec[i] + key )%26 + decrypt_string = ''.join(chr(i) for i in ascii_vals_dec) # To get the decrypted string using the list of manipulated ASCII vals + return decrypt_string + +def caesar_cipher(): + message = raw_input("Enter text to be encrypted:") + encrypt_string = encrypt(message,key) + decrypt_string = decrypt(encrypt_string,key) + print encrypt_string + print decrypt_string + +if __name__=="__main__": + key = int(raw_input("By what value do you want to shift?")) + caesar_cipher() From c2d3802077c0ad88c89cd8ab53fe8eb28ace96ba Mon Sep 17 00:00:00 2001 From: rahulkumaran Date: Fri, 8 Dec 2017 12:40:12 +0530 Subject: [PATCH 2/5] Delete Caesarcipher.py --- .../RSA Algortihm/Caesarcipher.py | 34 ------------------- 1 file changed, 34 deletions(-) delete mode 100644 Security Algorithms/Cryptography/RSA Algortihm/Caesarcipher.py diff --git a/Security Algorithms/Cryptography/RSA Algortihm/Caesarcipher.py b/Security Algorithms/Cryptography/RSA Algortihm/Caesarcipher.py deleted file mode 100644 index 6eeb5260e..000000000 --- a/Security Algorithms/Cryptography/RSA Algortihm/Caesarcipher.py +++ /dev/null @@ -1,34 +0,0 @@ -""" -A Caesar Cipher function for both, encryption and decryption. -After giving the string that you want, encryption will take place by shifting -characters to the right and the decrypted string can be obtained by shifting -the encrypted string to the left. -The cipher is ready for Capital Letters only -""" - -def encrypt(message,key): - ascii_vals_enc=[ord(c) for c in message] #To get a list of ASCII Values of each character in string - for i in range(0,len(ascii_vals_enc)): - if(ascii_vals_enc[i]>=65 and ascii_vals_enc[i]<=90): - ascii_vals_enc[i] = 65 + (ascii_vals_enc[i] + key - 91)%26 #If the values in the list are greater than 65 and 90, we get it back b/w 65 and 90 - encrypt_string = ''.join(chr(i) for i in ascii_vals_enc) # To get the encrypted string using the list of manipulated ASCII vals - return encrypt_string - -def decrypt(message,key): - ascii_vals_dec=[ord(c) for c in message] - for i in range(0,len(ascii_vals_dec)): - if(ascii_vals_dec[i]>=65 and ascii_vals_dec[i]<=90): - ascii_vals_dec[i] = 90 - (90 - ascii_vals_dec[i] + key )%26 - decrypt_string = ''.join(chr(i) for i in ascii_vals_dec) # To get the decrypted string using the list of manipulated ASCII vals - return decrypt_string - -def caesar_cipher(): - message = raw_input("Enter text to be encrypted:") - encrypt_string = encrypt(message,key) - decrypt_string = decrypt(encrypt_string,key) - print encrypt_string - print decrypt_string - -if __name__=="__main__": - key = int(raw_input("By what value do you want to shift?")) - caesar_cipher() From 6af7918f6deddf4353426d68237267a876af1204 Mon Sep 17 00:00:00 2001 From: rahulkumaran Date: Fri, 8 Dec 2017 13:04:23 +0530 Subject: [PATCH 3/5] Separate Python folder with Caesarcipher Algorithm Created a separate 'Python' folder under the cryptography folder and put the implementation of Caesarcipher in that folder. Also gave a custom input value for key and a custom string for encrypting and decrypting too. --- .../RSA Algortihm/Python/Caesarcipher.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Security Algorithms/Cryptography/RSA Algortihm/Python/Caesarcipher.py diff --git a/Security Algorithms/Cryptography/RSA Algortihm/Python/Caesarcipher.py b/Security Algorithms/Cryptography/RSA Algortihm/Python/Caesarcipher.py new file mode 100644 index 000000000..dff40b0cd --- /dev/null +++ b/Security Algorithms/Cryptography/RSA Algortihm/Python/Caesarcipher.py @@ -0,0 +1,41 @@ +""" +A Caesar Cipher function for both, encryption and decryption. +After giving the string that you want, encryption will take place by shifting +characters to the right and the decrypted string can be obtained by shifting +the encrypted string to the left. +The cipher is ready for Capital Letters only +""" + +def encrypt(message,key): + ascii_vals_enc=[ord(c) for c in message] #To get a list of ASCII Values of each character in string + for i in range(0,len(ascii_vals_enc)): + if(ascii_vals_enc[i]>=65 and ascii_vals_enc[i]<=90): + ascii_vals_enc[i] = 65 + (ascii_vals_enc[i] + key - 91)%26 #If the values in the list are greater than 65 and 90, we get it back b/w 65 and 90 + encrypt_string = ''.join(chr(i) for i in ascii_vals_enc) # To get the encrypted string using the list of manipulated ASCII vals + return encrypt_string + +def decrypt(message,key): + ascii_vals_dec=[ord(c) for c in message] + for i in range(0,len(ascii_vals_dec)): + if(ascii_vals_dec[i]>=65 and ascii_vals_dec[i]<=90): + ascii_vals_dec[i] = 90 - (90 - ascii_vals_dec[i] + key )%26 + decrypt_string = ''.join(chr(i) for i in ascii_vals_dec) # To get the decrypted string using the list of manipulated ASCII vals + return decrypt_string + +def caesar_cipher(): + #message_enc = raw_input("Enter text to be encrypted:") #Can be used to give custom strings + message_enc ="CODING IS FUN" #string to be encrypted + encrypt_string = encrypt(message_enc,key) #Calling the function to encrypt the string + print "The string to be encrypted is: ",message_enc + print "THe encrypted string is: ",encrypt_string + print "----------------------------------------" + #message_dec = raw_input("Enter text to be encrypted:") #Can be used to give custom strings + message_dec ="M PSZI GSHMRK" #string to be decrypted + decrypt_string = decrypt(message_dec,key) #Calling the function to decrypt the string + print "The string to be decrypted is: ",message_dec + print "THe decrypted string is: ",decrypt_string + +if __name__=="__main__": + #key = int(raw_input("By what value do you want to shift?")) #Can be used to give custom key values + key = 4 + caesar_cipher() From b26d0f6108515d5ce3d5238d375f94c4ae0d131b Mon Sep 17 00:00:00 2001 From: rahulkumaran Date: Fri, 8 Dec 2017 13:31:50 +0530 Subject: [PATCH 4/5] Delete Caesarcipher.py --- .../RSA Algortihm/Python/Caesarcipher.py | 41 ------------------- 1 file changed, 41 deletions(-) delete mode 100644 Security Algorithms/Cryptography/RSA Algortihm/Python/Caesarcipher.py diff --git a/Security Algorithms/Cryptography/RSA Algortihm/Python/Caesarcipher.py b/Security Algorithms/Cryptography/RSA Algortihm/Python/Caesarcipher.py deleted file mode 100644 index dff40b0cd..000000000 --- a/Security Algorithms/Cryptography/RSA Algortihm/Python/Caesarcipher.py +++ /dev/null @@ -1,41 +0,0 @@ -""" -A Caesar Cipher function for both, encryption and decryption. -After giving the string that you want, encryption will take place by shifting -characters to the right and the decrypted string can be obtained by shifting -the encrypted string to the left. -The cipher is ready for Capital Letters only -""" - -def encrypt(message,key): - ascii_vals_enc=[ord(c) for c in message] #To get a list of ASCII Values of each character in string - for i in range(0,len(ascii_vals_enc)): - if(ascii_vals_enc[i]>=65 and ascii_vals_enc[i]<=90): - ascii_vals_enc[i] = 65 + (ascii_vals_enc[i] + key - 91)%26 #If the values in the list are greater than 65 and 90, we get it back b/w 65 and 90 - encrypt_string = ''.join(chr(i) for i in ascii_vals_enc) # To get the encrypted string using the list of manipulated ASCII vals - return encrypt_string - -def decrypt(message,key): - ascii_vals_dec=[ord(c) for c in message] - for i in range(0,len(ascii_vals_dec)): - if(ascii_vals_dec[i]>=65 and ascii_vals_dec[i]<=90): - ascii_vals_dec[i] = 90 - (90 - ascii_vals_dec[i] + key )%26 - decrypt_string = ''.join(chr(i) for i in ascii_vals_dec) # To get the decrypted string using the list of manipulated ASCII vals - return decrypt_string - -def caesar_cipher(): - #message_enc = raw_input("Enter text to be encrypted:") #Can be used to give custom strings - message_enc ="CODING IS FUN" #string to be encrypted - encrypt_string = encrypt(message_enc,key) #Calling the function to encrypt the string - print "The string to be encrypted is: ",message_enc - print "THe encrypted string is: ",encrypt_string - print "----------------------------------------" - #message_dec = raw_input("Enter text to be encrypted:") #Can be used to give custom strings - message_dec ="M PSZI GSHMRK" #string to be decrypted - decrypt_string = decrypt(message_dec,key) #Calling the function to decrypt the string - print "The string to be decrypted is: ",message_dec - print "THe decrypted string is: ",decrypt_string - -if __name__=="__main__": - #key = int(raw_input("By what value do you want to shift?")) #Can be used to give custom key values - key = 4 - caesar_cipher() From b7499b13a3d1740c4bc47adf062309cfc6ff8bce Mon Sep 17 00:00:00 2001 From: rahulkumaran Date: Fri, 8 Dec 2017 13:34:17 +0530 Subject: [PATCH 5/5] Added a Caesarcipher folder under crypto Added a CaesarCipher folder, a python folder inside and inside that my code for the implementation of Caesarcipher(Caesarcipher.py) --- .../CaesarCipher/Python/Caesarcipher.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Security Algorithms/Cryptography/RSA Algortihm/CaesarCipher/Python/Caesarcipher.py diff --git a/Security Algorithms/Cryptography/RSA Algortihm/CaesarCipher/Python/Caesarcipher.py b/Security Algorithms/Cryptography/RSA Algortihm/CaesarCipher/Python/Caesarcipher.py new file mode 100644 index 000000000..dff40b0cd --- /dev/null +++ b/Security Algorithms/Cryptography/RSA Algortihm/CaesarCipher/Python/Caesarcipher.py @@ -0,0 +1,41 @@ +""" +A Caesar Cipher function for both, encryption and decryption. +After giving the string that you want, encryption will take place by shifting +characters to the right and the decrypted string can be obtained by shifting +the encrypted string to the left. +The cipher is ready for Capital Letters only +""" + +def encrypt(message,key): + ascii_vals_enc=[ord(c) for c in message] #To get a list of ASCII Values of each character in string + for i in range(0,len(ascii_vals_enc)): + if(ascii_vals_enc[i]>=65 and ascii_vals_enc[i]<=90): + ascii_vals_enc[i] = 65 + (ascii_vals_enc[i] + key - 91)%26 #If the values in the list are greater than 65 and 90, we get it back b/w 65 and 90 + encrypt_string = ''.join(chr(i) for i in ascii_vals_enc) # To get the encrypted string using the list of manipulated ASCII vals + return encrypt_string + +def decrypt(message,key): + ascii_vals_dec=[ord(c) for c in message] + for i in range(0,len(ascii_vals_dec)): + if(ascii_vals_dec[i]>=65 and ascii_vals_dec[i]<=90): + ascii_vals_dec[i] = 90 - (90 - ascii_vals_dec[i] + key )%26 + decrypt_string = ''.join(chr(i) for i in ascii_vals_dec) # To get the decrypted string using the list of manipulated ASCII vals + return decrypt_string + +def caesar_cipher(): + #message_enc = raw_input("Enter text to be encrypted:") #Can be used to give custom strings + message_enc ="CODING IS FUN" #string to be encrypted + encrypt_string = encrypt(message_enc,key) #Calling the function to encrypt the string + print "The string to be encrypted is: ",message_enc + print "THe encrypted string is: ",encrypt_string + print "----------------------------------------" + #message_dec = raw_input("Enter text to be encrypted:") #Can be used to give custom strings + message_dec ="M PSZI GSHMRK" #string to be decrypted + decrypt_string = decrypt(message_dec,key) #Calling the function to decrypt the string + print "The string to be decrypted is: ",message_dec + print "THe decrypted string is: ",decrypt_string + +if __name__=="__main__": + #key = int(raw_input("By what value do you want to shift?")) #Can be used to give custom key values + key = 4 + caesar_cipher()