Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Cryptography/Caesarcipher.py
Original file line number Diff line number Diff line change
@@ -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()
50 changes: 50 additions & 0 deletions bitmanip.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include<stdio.h>
#define baseyear 2000

void main()
{
short int date;
short int temp,retrieve;


printf("Enter Date:\n");
scanf("%d",&temp);
date=temp;

printf("Enter Month:\n");
scanf("%d",&temp);
date=date|(temp<<5);

/*printf("%d\n",date);
printf("%d %d",temp,retrieve);*/

printf("Enter Year:\n");
scanf("%d",&temp);
date=date|(temp-baseyear)<<9;

printf("The total date information stored in 2 bytes has been encoded as follows: %d\n",date);


retrieve=(date<<11);
retrieve=retrieve>>11;
if(retrieve<0)
printf("The date is : %d\n",32+retrieve);
else
printf("The date is : %d\n",retrieve);


retrieve=date<<7;
retrieve=retrieve>>12;
if(retrieve<0)
printf("The month is : %d\n",16+retrieve);
else
printf("The month is : %d\n",retrieve);


retrieve=date>>9;
if(retrieve<0)
printf("The year is : %d\n",128+retrieve+baseyear);
else
printf("The year is : %d\n",retrieve+baseyear);

}
29 changes: 29 additions & 0 deletions sort/shellsort.py
Original file line number Diff line number Diff line change
@@ -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