Cyber Practical
Cyber Practical
Cyber Practical
Write an algorithm and Program for encrypting a plain text and decrypting a cipher text using
Caesar Cipher.
The Caesar Cipher technique is one of the earliest and simplest method of encryption technique. It’s
simply a type of substitution cipher, i.e., each letter of a given text is replaced by a letter some fixed number
of positions down the alphabet.
For example with a shift of 1, A would be replaced by B, B would become C, and so on. The method is
apparently named after Julius Caesar, who apparently used it to communicate with his officials.
Thus to cipher a given text we need an integer value, known as shift which indicates the number of position
each letter of the text has been moved down.
The encryption can be represented using modular arithmetic by first transforming the letters into numbers,
according to the scheme, A = 0, B = 1… Z = 25. Encryption of a letter by a shift n can be described
mathematically as.
Where,
E denotes the encryption
D denotes the decryption
x denotes the letters value
n denotes the key value (shift value)
Examples :
Text : ABCDEFGHIJKLMNOPQRSTUVWXYZ
Shift: 23
Cipher: XYZABCDEFGHIJKLMNOPQRSTUVW
Text : ATTACKATONCE
Shift: 4
Cipher: EXXEGOEXSRGI
Example: 2 Use the Caesar cipher to encrypt and decrypt the message "HELLO," and the key (shift) value
of this message is 15.
Encryption
We apply encryption formulas by character, based on alphabetical order.
En (x) = (x + n) mod 26
Decryption
#include<stdio.h>
#include<conio.h>
int main()
{
int i, f;
char pop[100], c;
printf(" enter a plaintext \n");
gets(pop);
printf("enter key");
scanf("%d", &f);
for(i = 0; pop[i] ! = '\0'; i++)
{
c = pop[i];
if(c >= 'a' && c <= 'z')
{
c = c + f;
if(c > 'z')
{
c = c - 'z' + 'a' - 1;
}
pop[i] = c;
}
else if(c >= 'A' && c < 'Z')
{
c = c + f;
if(c > 'Z')
{
c = c = 'Z' + 'A' - 1;
}
pop[i] = c;
}
}
printf(" Encrypted message: %s", pop);
return 0;
}
C program for the decryption
#include<stdio.h>
#include<conio.h>
int main()
{
int i, f;
char pop[100], c;
printf("enter a encrypted test \t");
gets(pop);
printf("enter key \t");
scanf("%d", &f);
for(i = 0; pop[i] != '\0'; i++)
{
c = pop[i];
if(c >= 'a' && c <= 'z')
{
c = c - f;
if(c < 'a')
{
c = c + 'z' - 'a' + 1;
}
pop[i] = c;
}
else if(c >= 'A' && c < 'Z')
{
c = c + f;
if(c < 'A')
{
c = c + 'Z' - 'A' + 1;
}
pop[i] = c;
}
}
printf(" Dycrypted message: %s", pop);
return 0;
}
From the above presentation create the remaining presentations by taking content from your notes
Create a Presentation on “Cyber Security Regulations” with at least 10 slides
Create a Presentation on “Role of International Law” with at least 10 slides
Create a Presentation on “Cyber Forensics” with at least 10 slides
Create a Presentation on “Cyber Security Standards” with at least 10 slides
Create a Presentation on “Cyber Security Attacks” with at least 10 slides
Create a Presentation on “Cyber Security Policies 2013” with at least 10 slides
12. What is Malware? Write the steps to remove the malware from your PC.
Malware (short for “malicious software”) is a file or code, typically delivered over a network, that
infects, explores, steals or conducts virtually any behavior an attacker wants. And because malware
comes in so many variants, there are numerous methods to infect computer systems.
Though varied in type and capabilities, malware usually has one of the following objectives:
ALGORITHM:
STEP-1: Read the 64-bit plain text.
STEP-2: Split it into two 32-bit blocks and store it in two different arrays.
STEP-3: Perform XOR operation between these two arrays.
STEP-4: The output obtained is stored as the second 32-bit sequence and the original second 32-bit sequence
forms the first part.
STEP-5: Thus the encrypted 64-bit cipher text is obtained in this way. Repeat the same process for the
remaining plain text characters.
14. To write a C program to implement the RSA encryption algorithm.
RSA is an algorithm used by modern computers to encrypt and decrypt messages. It is an asymmetric
cryptographic algorithm. Asymmetric means that there are two different keys. This is also called public key
cryptography, because one of them can be given to everyone. A basic principle behind RSA is the
observation that it is practical to find three very large positive integers e, d and n such that with modular
exponentiation for all integer m:
(me)d = m (mod n)
The public key is represented by the integers n and e; and, the private key, by the integer d. m represents the
message. RSA involves a public key and a private key. The public key can be known by everyone and is
used for encrypting messages. The intention is that messages encrypted with the public key can only be
decrypted in a reasonable amount of time using the private key.
ALGORITHM:
STEP-1: Select two co-prime numbers as p and q.
STEP-2: Compute n as the product of p and q.
STEP-3: Compute (p-1)*(q-1) and store it in z.
STEP-4: Select a random prime number e that is less than that of z.
STEP-5: Compute the private key, d as e * mod-1(z).
STEP-6: The cipher text is computed as message^e * mod n.
STEP-7: Decryption is done as cipher mod n.
PROGRAM: (RSA)
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
long int
p,q,n,t,flag,e[100],d[100],temp[100],j,m[100],en[100],i;
char msg[100];
int prime(long int);
void ce();
long int cd(long int);
void encrypt();
void decrypt();
void main()
{
clrscr();
printf("\nENTER FIRST PRIME NUMBER\n");
scanf("%d",&p);
flag=prime(p);
if(flag==0)
{
printf("\nWRONG INPUT\n");
getch();
}
printf("\nENTER ANOTHER PRIME NUMBER\n");
scanf("%d",&q);
flag=prime(q);
if(flag==0||p==q)
{
printf("\nWRONG INPUT\n");
getch();
}
printf("\nENTER MESSAGE\n");
fflush(stdin);
scanf("%s",msg);
for(i=0;msg[i]!=NULL;i++)
m[i]=msg[i];
n=p*q;
t=(p-1)*(q-1);
ce();
printf("\nPOSSIBLE VALUES OF e AND d ARE\n");
for(i=0;i<j-1;i++)
printf("\n%ld\t%ld",e[i],d[i]);
encrypt();
decrypt();
getch();
}
int prime(long int pr)
{
int i;
j=sqrt(pr);
for(i=2;i<=j;i++)
{
if(pr%i==0)
return 0;
}
return 1;
}
void ce()
{
int k;
k=0;
for(i=2;i<t;i++)
{
if(t%i==0)
continue;
flag=prime(i);
if(flag==1&&i!=p&&i!=q)
{
e[k]=i;
flag=cd(e[k]);
if(flag>0)
{
d[k]=flag;
k++;
}
if(k==99)
break;
}}}
long int cd(long int x)
{
long int k=1;
while(1)
{
k=k+t;
if(k%x==0)
return(k/x);
}}
void encrypt() {
long int pt,ct,key=e[0],k,len;
i=0;
len=strlen(msg);
while(i!=len) {
pt=m[i];
pt=pt-96;
k=1;
for(j=0;j<key;j++)
{ k=k*pt;
k=k%n;
}
temp[i]=k;
ct=k+96;
en[i]=ct;
i++;
}
en[i]=-1;
printf("\nTHE ENCRYPTED MESSAGE IS\n");
for(i=0;en[i]!=-1;i++)
printf("%c",en[i]);
}
void decrypt()
{
long int pt,ct,key=d[0],k;
i=0;
while(en[i]!=-1)
{
ct=temp[i];
k=1;
for(j=0;j<key;j++)
{
k=k*ct;
k=k%n;
}
pt=k+96;
m[i]=pt;
i++;
}
m[i]=-1;
printf("\nTHE DECRYPTED MESSAGE IS\n");
for(i=0;m[i]!=-1;i++)
printf("%c",m[i]);
}