-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
155b9aa
commit 2b46e3a
Showing
4 changed files
with
373 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Progam for encryption and decryption using Caesar cipher technique without key // | ||
#include <stdio.h> | ||
#include <conio.h> | ||
#include <string.h> | ||
void main() | ||
{ | ||
char plain[50]; | ||
char cipher[50]; | ||
char c; | ||
int key = 3,i,j; | ||
clrscr(); | ||
printf("Enter Plain Text ="); | ||
gets(plain); | ||
|
||
// Encryption Logic | ||
for(i=0; i<strlen(plain); i++); | ||
{ | ||
if(plain[i]>='A' && plain[i]<='Z') | ||
{ | ||
cipher[i]=((plain[i]-65+key) % 26)+65; | ||
printf("%c",cipher[i]); | ||
} | ||
else if(plain[i]>='a' && plain[i]<='z') | ||
{ | ||
cipher[i]=((plain[i]-97+key) % 26)+97; | ||
printf("%c",cipher[i]); | ||
} | ||
else | ||
{ | ||
cipher[i] = plain[i]; | ||
printf("%c",plain[i]); | ||
} | ||
} | ||
printf("\n\n"); | ||
|
||
// Decryption Logic | ||
printf("Decryption is ="); | ||
for(i=0;i<strlen(plain);i++) | ||
{ | ||
if(cipher[i]>='A' && cipher[i]<='Z') | ||
{ | ||
plain[i]=((cipher[i]-65-key) % 26)+65; | ||
printf("%c",plain[i]); | ||
} | ||
else if(plain[i]>='a' && plain[i]<='z') | ||
{ | ||
plain[i]=((cipher[i]-97-key) % 26)+97; | ||
printf("%c",plain[i]); | ||
} | ||
else | ||
{ | ||
cipher[i] = plain[i]; | ||
printf("%c",cipher[i]); | ||
} | ||
} | ||
getch(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Encryption and Decryption using columnar transposition // | ||
|
||
#include<stdio.h> | ||
#include<conio.h> | ||
void main() | ||
{ | ||
char pt[60]; | ||
char newpt[60] = {"\0"}; | ||
char et[60] = {"\0"}; | ||
char newet[60] = {"\0"}; | ||
char dt[60] = {"\0"}; | ||
char mat[12][5]; | ||
int row, column = 5, len, i, j, newlen, k = 0, m; | ||
clrscr(); | ||
printf("\n\nEnter Plain Text:"); | ||
gets(pt); | ||
|
||
len = strlen(pt); | ||
for(i=0; i<len; i++) | ||
{ | ||
if(pt[i] != 32) | ||
30 | ||
{ | ||
newlen = strlen(newpt); | ||
newpt[newlen] = pt[i]; | ||
} | ||
} | ||
// Getting Size of Row // | ||
newlen - strlen(newpt); | ||
row = newlen/column; | ||
if(newlen % column > 0) | ||
row = row + 1; | ||
|
||
// Create matrix from plaintext // | ||
printf("\nColumner Matrix is:"); | ||
for(i = 0; i < row; i++) | ||
{ | ||
for(j = 0; j < column; j++) | ||
{ | ||
if(k < newlen) | ||
{ | ||
mat[i][j] = newpt[k]; | ||
printf("%2c",newpt[k]); | ||
k++; | ||
}else{ | ||
mat[i][j] = 32; | ||
} | ||
} | ||
printf("\n"); | ||
} | ||
// Encryption Code // | ||
k = 0; | ||
for(m = 0; m < column; m += 2) | ||
{ | ||
for(i = 0; i < row; i++) | ||
{ | ||
et[k] = mat[i][m]; | ||
k++; | ||
} | ||
} | ||
for(m = 1; m < column; m += 2) | ||
{ | ||
for(i = 0; i < row; i++) | ||
{ | ||
et[k] = mat[i][m]; | ||
k++; | ||
} | ||
31 | ||
} | ||
|
||
// Blank space Remove Code // | ||
newlen = strlen(et); | ||
for(i = 0; i < newlen; i++) | ||
{ | ||
if(et[i] != 32) | ||
{ | ||
len = strlen(newet); | ||
newet[len] = et[i]; | ||
} | ||
} | ||
printf("\n\nEncrypted Text Is: %s", newet); | ||
|
||
// Decryption Code // | ||
k = 0; | ||
for(i = 0; i < row; i++) | ||
{ | ||
m = i; | ||
for(j = 0; j < column; j++) | ||
{ | ||
if(j%2 == 0) | ||
{ | ||
dt[k] = et[m]; | ||
m = m + (row * 3); | ||
k++; | ||
|
||
} | ||
else{ | ||
dt[k] = et[m]; | ||
m = m - (row * 2); | ||
k++; | ||
} | ||
} | ||
} | ||
printf("\n\n Decrypted Text Is: %s", dt); | ||
getch(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// Program for Encryption and Decryption using Hill Cipher technique // | ||
|
||
#include<stdio.h> | ||
#include<conio.h> | ||
#include<string.h> | ||
void main() | ||
{ | ||
char ptext[20] = "\0", newptext[20] = "\0", etext[20] = "\0", newetext[20] = "\0", | ||
dtext[20] = "\0", newdtext[20] = "\0", abcd[26] = "abcdefghijklmnopqrstuvwxyz"; | ||
|
||
int b[20], c[20], newmod[20], mod[20], mat[3][3], a[9]; | ||
int A, i, j ,len ,len1 ,oldlen , sum = 0 , k = 0, x, y, div, DIV, m , n = 0; | ||
clrscr(); | ||
|
||
// Enter Plain Text // | ||
printf("Enter the plain text:"); | ||
gets(ptext); | ||
|
||
// Remove Blank Space // | ||
oldlen = strlen(ptext); | ||
for(k = 0; k < oldlen; k++) | ||
{ | ||
if(ptext[k] != 32) | ||
{ | ||
len1 = strlen(newptext); | ||
newptext[len1] = ptext[k]; | ||
} | ||
} | ||
|
||
// Add Two Fake or Dummy Character for Grouping of 3 Character // | ||
oldlen = strlen(newptext); | ||
newptext[oldlen] = 'x'; | ||
newptext[oldlen + 1] = 'x'; | ||
len = strlen(newptext); | ||
|
||
// Enter Values of Matrix // | ||
printf("\n Enter values of 3 X 3 array:\n"); | ||
for(i = 0; i < 3; i++) | ||
{ | ||
for(j = 0; j < 3; j++) | ||
{ | ||
scanf("%d",&mat[i][j]); | ||
} | ||
} | ||
|
||
// Encryption Start here // | ||
for(m = 1; m <= len; m++) | ||
{ | ||
if(m % 3 == 0) | ||
{ | ||
for(i = n; i < n+3; i++) | ||
{ | ||
for(j = 0; j < 26; j++) // It will get index of plaintext | ||
{ | ||
if(newptext[i] == abcd[j]); | ||
{ | ||
b[i % 3] = j; | ||
break; | ||
} | ||
} | ||
} | ||
for(i = 0; i < 3; i++) | ||
{ | ||
for(j = 0; j < 3; j++) | ||
{ | ||
sum = sum + (b[j] * mat[i][j]); | ||
} | ||
mod[i] = sum % 26; | ||
sum = 0; | ||
} | ||
// Creating Text From Modulied Matrix // | ||
for(i = n; i < n +3; i++) | ||
{ | ||
for(j = 0; j < 26; j++) | ||
{ | ||
if(mod[i % 3] == j) | ||
{ | ||
etext[i] = abcd[j]; | ||
break; | ||
} | ||
} | ||
} | ||
n = n + 3; | ||
} | ||
} | ||
// Remove Extra Character From End of etext // | ||
for(i = 0; i < oldlen; i++){ | ||
newetext[i] = etext[i]; | ||
} | ||
// Print Encrypted Text // | ||
printf("\n Encrypted Text is :"); | ||
puts(newetext); | ||
|
||
// Inverse of matrix for decryption // | ||
A = (mat[0][0] * (mat[1][1] * mat[2][2] - mat[2][1] * mat[1][2])) - (mat[0][1] * (mat[1][0] | ||
* mat[2][2] - mat[2][0] * mat[1][2])) + (mat[0][2] * (mat[1][0] * mat[2][1] - mat[2][0] * mat[1][1])); | ||
|
||
div = A/26; | ||
if(div < 0) | ||
{ | ||
DIV = div - 1; | ||
} | ||
else{ | ||
DIV = div; | ||
} | ||
A = A-26 * DIV; | ||
printf("\n Value of a is %d\n\n",A); | ||
for(x = 1; x < 1000; x++) | ||
{ | ||
if(y * 26 == A*x-1) | ||
{ | ||
goto xy; | ||
} | ||
} | ||
xy: | ||
printf("\n x = %d y = %d \n\n",x,y); | ||
a[0] = (mat[1][1] * mat[2][2] - mat[2][1] * mat[1][2]); | ||
a[3] = -(mat[1][0] * mat[2][2] - mat[2][0] * mat[1][2]); | ||
a[6] = (mat[1][0] * mat[2][1] - mat[2][0] * mat[1][1]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Progam for Encryption and Decryption using Vigener Cipher technique // | ||
|
||
#include <stdio.h> | ||
#include <conio.h> | ||
#include <string.h> | ||
void main() | ||
{ | ||
char str[100]; | ||
char cstr[100]; | ||
char code[5] = "SSPC",c; | ||
char cap_code[5] = "SSPC"; | ||
int indexcode = 0, ascii; | ||
int i,j,number,a,b, len = 0; | ||
clrscr(); | ||
printf("\n\n\t\tEnter Plain Text = "); | ||
gets(str); | ||
i = strlen(str); | ||
len = strlen(code) - 1; | ||
for(j = 0; j < i; j++) | ||
{ | ||
if(str[j] != '') | ||
{ | ||
ascii = (int)str[j]; | ||
if(ascii >= 65 && ascii <=90) | ||
{ | ||
int index = indexcode % len; | ||
cstr[j] = code[index]; | ||
} | ||
indexcode++; | ||
} | ||
else | ||
cstr[j] = ''; | ||
} | ||
cstr[j] = '\0'; | ||
printf("\n\n\t\tKey Code = "); | ||
puts(cstr) | ||
for(j = 0; j < i; j++) | ||
{ | ||
ascii = (int)str[j]; | ||
if(str[j] != '') | ||
{ | ||
if(ascii >= 65 && ascii <= 90) | ||
{ | ||
a = (int)str[j] % 65; | ||
b = (int)cstr[j] % 65; | ||
number = (a + b) % 26; | ||
number = number + 97; | ||
} | ||
else if(ascii >= 97 && ascii <= 122) | ||
{ | ||
a = (int)str[j] % 97; | ||
b = (int)cstr[j] % 97; | ||
number = (a + b) % 26; | ||
number = number + 97; | ||
} | ||
str[j] = (char) number; | ||
} | ||
else str[j] = ''; | ||
} | ||
str[j] = '\0'; | ||
printf("\n\n\t\tEncrypted Text = "); | ||
puts(str); | ||
for(j = 0; j++) | ||
{ | ||
ascii = (int)str[j]; | ||
if(str[j] != '') | ||
{ | ||
if(ascii >= 65 && ascii <= 90) | ||
{ | ||
a = (int)str[j] % 65; | ||
b = (int)cstr[j] % 65; | ||
number = (a + b) % 26; | ||
number = number + 97; | ||
} | ||
else if(ascii >= 97 && ascii <= 122) | ||
{ | ||
a = (int)str[j] % 97; | ||
b = (int)cstr[j] % 97; | ||
number = (a + b) % 26; | ||
number = number + 97; | ||
} | ||
str[j] = (char) number; | ||
} | ||
else str[j] = ''; | ||
} | ||
str[j] = '\0'; | ||
printf("\n\n\t\tPlain Text = "); | ||
puts(str); | ||
getch(); | ||
} |