Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code for shell sort in python #89

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
dffcc1e
Added a code for Caesar Cipher
rahulkumaran Dec 2, 2017
98eb1f2
removed a few loops
rahulkumaran Dec 2, 2017
6ece6c4
Update caesarcipher.py
rahulkumaran Dec 2, 2017
743965d
Update caesarcipher.py
rahulkumaran Dec 2, 2017
4d54161
Delete caesarcipher.py
rahulkumaran Dec 2, 2017
65070fa
Add files via upload
rahulkumaran Dec 2, 2017
6c8d15e
Update caesarcipheropt.py
rahulkumaran Dec 2, 2017
e1417a7
Update caesarcipheropt.py
rahulkumaran Dec 2, 2017
6d4c36f
Delete caesarcipheropt.py
rahulkumaran Dec 2, 2017
35f90b8
Add files via upload
rahulkumaran Dec 2, 2017
d31a290
Update caesarcipher1.py
rahulkumaran Dec 2, 2017
770238a
Update caesarcipher1.py
rahulkumaran Dec 2, 2017
eddd0a6
Update caesarcipher1.py
rahulkumaran Dec 2, 2017
9637e87
Delete caesarcipher1.py
rahulkumaran Dec 2, 2017
ebe4221
Add files via upload
rahulkumaran Dec 2, 2017
f38609f
Cleared whitespaces
rahulkumaran Dec 2, 2017
24c9192
Update Caesarcipher.py
rahulkumaran Dec 2, 2017
4370066
Code for Shell Sort
rahulkumaran Dec 2, 2017
8794cbc
Create bit manipulation
rahulkumaran Dec 2, 2017
2561215
Merge pull request #1 from codeIIEST/master
rahulkumaran Dec 6, 2017
e830706
Delete Caesarcipher.py
rahulkumaran Dec 6, 2017
c8939cf
Delete shellsort.py
rahulkumaran Dec 6, 2017
e6cc494
Added code for Ceasarcipher
rahulkumaran Dec 6, 2017
a27809c
Delete bit manipulation
rahulkumaran Dec 6, 2017
bb26500
Code for Shell Sort
rahulkumaran Dec 6, 2017
458d706
Update Caesarcipher.py
rahulkumaran Dec 6, 2017
66520eb
Update Caesarcipher.py
rahulkumaran Dec 6, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions Competitive Coding/Sorting/Shell_Sort/shellsort.py
@@ -0,0 +1,29 @@
"""
The algorithm uses a procedure called Shell Sort
to sort the lists. It breaks the list to smaller sublists
and each sublist is further sorted by insertion sort.
The sublists are made using a gap and elements at gap i
is often selected and forms a sublist.
"""

def shellSort(test):
sublistcount = len(test)//2 #Finds gap to create sublists
while(sublistcount > 0):
for startposition in range(sublistcount):
gapInsertionSort(test,startposition,sublistcount)
print("After increments of size",sublistcount,"The list is",test)
sublistcount = sublistcount // 2

def gapInsertionSort(test,start,gap):
for i in range(start+gap,len(test),gap):
currentvalue = test[i]
position = i
while(position>=gap and test[position-gap]>currentvalue):
test[position]=test[position-gap]
position = position-gap
test[position]=currentvalue

if __name__=="__main__":
test = [99,109,29,89,44,98,20,55,31]
shellSort(test)
print test
34 changes: 34 additions & 0 deletions 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()