complete lab programs

Upload: md2829

Post on 14-Apr-2018

237 views

Category:

Documents


1 download

TRANSCRIPT

  • 7/28/2019 Complete Lab Programs

    1/71

    EXPERIMENT NUMBER 1:

    Working with Sniffers for monitoring network communication (Ethereal)

    Procedure to show all the captured packets:

    Step 1: Click on the icon that is provided the ethereal tool.

    Step 2: Go to capture and then click on interface.

    Step 3: A dialogue box with capture and prepare options with appear. Click on capture.

    Step 4: Another dialogue box with a list of all various types of packets that are to be captured

    within duration of time will be shown.

    Step 5: Take a required duration say about 1 min to 10 min until some of the packets are

    captured and then click on stop.

    Step 6: A list of all the different packets that were captured in the required duration will be

    obtained.

    Step 7: Finally, save the file with same name and with a .cap extension.

    Procedure to describe a particular packet in octail:

    Step 1: Click on the icon that is provided the ethereal tool.

    Step 2: Go to capture and then click on interface.

    Step 3: A dialogue box with capture and prepare options with appear. Click on capture.

    Step 4: Another dialogue box with a list of all various types of packets that are to be captured

    within duration of time will be shown.

    Step 5: Take a required duration say about 1 min to 10 min until some of the packets are

    captured and then click on stop.

  • 7/28/2019 Complete Lab Programs

    2/71

    Step 6: A list of all the different packets that were captured in the required duration will be

    obtained.

    Step 7: Right click on any of the packets and click on show packet in new window

    Step 8: Finally, save the file with same name and with a .cap extension.

    Procedure to display the flow graph:

    Step 1: Click on the icon that is provided the ethereal tool.

    Step 2: Go to capture and then click on interface.

    Step 3: A dialogue box with capture and prepare options will appear. Click on capture.

    Step 4: Another dialogue box with a list of all various types of packets that are to be captured

    within duration of time will be shown.

    Step 5: Take a required duration say about 1 min to 10 min until some of the packets are

    captured and then click on stop.

    Step 6: A list of all the different packets that were captured in the required duration will be

    obtained.

    Step 7: Now click on statistics and then on flow graphs to get the graphical representation of the

    captured packets.

    Step 8: Finally, save the file with same name and with a .cap extension.

  • 7/28/2019 Complete Lab Programs

    3/71

    EXERIMENT NUMBER 2:

    Understanding cryptographic algorithms and implementation the same in C or C++

    /*CEASER CIPHER */

    #include

    #include

    #include

    #include

    void main()

    {

    int i,j,k,l,ct[30],n;

    char pt[30],a[26]={ 'a','b','c','d','e','f','g','h','i','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

    clrscr();

    printf("enter plain text :\n");

    scanf("%s",&pt);

    l=strlen(pt);

    printf("enter the key:\n");

    scanf("%d",&k);

    for(i=0;i

  • 7/28/2019 Complete Lab Programs

    4/71

    {

    if(pt[i]==a[j])

    {

    ct[i]=(j+k)%26;

    break;

    }

    }

    }

    printf("Encryption:\n");

    printf("Cipher text is:\n");

    for(i=0;i

  • 7/28/2019 Complete Lab Programs

    5/71

  • 7/28/2019 Complete Lab Programs

    6/71

    TEXT DATA:

    Example 1:

    Enter Plain text :

    college

    Enter the key

    23

    Encryption:

    Cipher text is:

    ZLIIBDB

    Decryption:

    Plain text is:

    college

  • 7/28/2019 Complete Lab Programs

    7/71

    /* TRANSPOSITION CIPHER */

    # include

    #include

    #include

    #include

    #include

    char alpha[26]={ 'a','b','c','d','e','f','g','h','i','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

    void main()

    {

    int row,i,j,k,len,l=0,y=0,x=0,n[20],min,count[20]={0};

    float col;

    char p11[50],p12[50],ci[50],key[20],mat[20][20],matbuf[20][20]={0};

    clrscr();

    printf("\n enter the plain text :");

    scanf("%s",p11);

    printf("\n enter the key:");

    scanf("%s",key);

    col=strlen(key);

    row=ceil(strlen(p11/col));

    x=strlen(p11)%strlen(key);

  • 7/28/2019 Complete Lab Programs

    8/71

    y=strlen(p11)-x;

    l=strlen(p11);

    len=strlen(p11);

    for(i=0;i

  • 7/28/2019 Complete Lab Programs

    9/71

    {

    if(key[i]==alpha[j])

    n[i]=j;

    }

    }

    for(j=0;j

  • 7/28/2019 Complete Lab Programs

    10/71

    {

    for(j=0;j

  • 7/28/2019 Complete Lab Programs

    11/71

    l=0;

    for(i=0;i

  • 7/28/2019 Complete Lab Programs

    12/71

    l++;

    }

    printf("\n");

    }

    printf("\n\n obtained plaintext is :\n\n");

    for(i=0;i

  • 7/28/2019 Complete Lab Programs

    13/71

    TEST DATA

    Input: enter the plain text

    John please transfer thousands rupees to joes account

    Enter the key arnold.

    Output: Encryption

    Arnold

    164532

    Johnpl

    Easetr

    Ansfer

    Thousa

    Hdrupe

    Estojo esacco

    Untadd

    Decryption

    Enter the cipher text

    Jeantnceulrraeoodptespjedhssprtaafne fuuocdoanhdssn

    Johpl

    Easetr

    Ansfer

  • 7/28/2019 Complete Lab Programs

    14/71

    Thousahdrupe

    Estojo

    Untddd

    Obtained plaintext is:

    John please transfer thousand rupes to joes account.

  • 7/28/2019 Complete Lab Programs

    15/71

    EXPERIMENT NUMBER 3:

    Using openssl for web server-browser communication

    Write a program to implement tcp/tp client

    #include

    #include

    #include

    #include

    #include

    main()

    {

    char buf[200];

    char *serv_ip=127.0.0.1;

    int n;

    int soctfd ,ret_val;

    struct sockaddr_in servaddr;

    sockfd=socket(AF_INET,SOCK_STREAM,0);

    bzero(&servaddr,sizeof(servaddr));

    servaddr.sin_family=AF_INET;

    servaddr.sin_port=htons(8001);

    inet_pton(AF_INET,serv_ip,&servaddr.sin_addr);

    ret_val=connect(sockfd,(Struct sockaddr *) &servaddr,size of(servaddr));

  • 7/28/2019 Complete Lab Programs

    16/71

    if(ret_val

  • 7/28/2019 Complete Lab Programs

    17/71

    TEST DATA

    Enter data that you want to send the server WELCOME

    Received goodbye from server

    Write a program to implement tcp/ip server

  • 7/28/2019 Complete Lab Programs

    18/71

    #include

    #include

    #include

    #include

    #include

    main()

    {

    int listfd,connfd,retval;

    pid_t childpid;

    socklen_t clilen;

    struct sockaddr_in.cliaddr,servaddr;

    listfd=socket(AF_INET,SOCK_STREAM,0);

    if(listfd

  • 7/28/2019 Complete Lab Programs

    19/71

    retval=bind(listfd,(struct sock addr *)& servaddr,sizeof(servaddr));

    if(retval

  • 7/28/2019 Complete Lab Programs

    20/71

    buf[n]=\0;

    printf( data read from client =%s \n,buf);

    exit(0);

    }

    close(connfd);

    }

    }

    TEST DATA

    Client conn

    Data read from client=WELCOME

    EXPERIMENT NUMBER 4:

    Using PGP-GNU

    Message sent from the same sender

    C:\Program files\GNU\GNUPG>gpgversion

  • 7/28/2019 Complete Lab Programs

    21/71

  • 7/28/2019 Complete Lab Programs

    22/71

    3) RSA (sign only)

    Your selection?1

    DSA keypair will have 1024 bits

    ELG-E keys may be between 1024 and 4096 bits long

    What keysize do you want?(2048)1024

    Requested keysize is 1024 bits

    Please specify how long the key should b valid

    0 = key doest not expire

    = key expires in n days

    w = key expires in n weeks

    m = key expires in n months

    y = key expires in n years

    key is valid for ?(0) 9

    key expires at 04/10/09 14:37:27

    Is this correct ?(Y/N) Y

    Message sent from a sender to receiver

    C:\Program files\GNU\GNUPG>

    C:\Program files\GNU\GNUPG>gpg- -gen-key

    Gpg(GNUPG)1.4.9

  • 7/28/2019 Complete Lab Programs

    23/71

    Copyright(c) 2008 Free software foundation, Inc

    License GPL v3+: GNU GPL version 3 or laterhttp://gnu.org/license/gpl.html

    This is free software: you are free to change and redistribute it.

    There is no warranty to the extent permitted by law.

    Please select what kind of key you want:

    1) DSA and Elgamal(default)

    2) DSA (sign only)

    3) RSA (sign only)Your selection?1

    DSA keypair will have 1024 bits

    ELG-E keys may be between 1024 and 4096 bits long

    What keysize do you want?(2048)1024

    Requested keysize is 1024 bits

    Please specify how long the key should b valid

    0 = key doest not expire

    = key expires in n days

    w = key expires in n weeks

    m = key expires in n months

    y = key expires in n years

    key is valid for ?(0) 9

    key expires at 04/10/09 14:47:36

    http://gnu.org/license/gpl.htmlhttp://gnu.org/license/gpl.html
  • 7/28/2019 Complete Lab Programs

    24/71

    Is this correct ?(Y/N) Y

    You need a user ID to identify your key; the software constructs the user ID from the real Name,

    Comment and Email Address in this form:

    Heinrick Hein (derDitcher)

    Real name: kiran

    Email Address: [email protected]

    Comment hello world

    You selected this user ID: kiran(hello world)

    Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? 0

    You need a passphrase to protect your secret key.

    We need to generate a lot of random bytes. It is a good idea to perform some other action during

    the prime generation: this gives the random number generator a better chance to gain entropy

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +> + ++ + + + + + + + +> + + + + + + + +. . . . . . + + + +

    We need to generate a lot of random bytes. It is a good idea to perform some other action during

    the prime generation: this gives the random number generator a better chance to gain entropy

    . + + + + + + + + + + + +.

    gpg: key 1D5924EB marked as ultimately trusted public and secret key created and signed.

    gpg: checking the trustdb.

    gpg: depth:0 valid:5 signed:0 trust:0-, 0q, 0n, 0m, 0f, 5u.

    gpg: next trustdb ckeckdue at 2009-04-10 pub 1024/1D5924EB 2009-04-01

    [Expires: 2009-04-01]

    mailto:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]
  • 7/28/2019 Complete Lab Programs

    25/71

    Key fingerprint = D615 12FD C48F 652E CB73 5628 B870 C6C5 1D59 24EB

    Uid: Kiran(hello world)[email protected]

    Sub 1024/4F1C8D75 2009-04-01 [Expires: 2009-04-01]

    C:\Program files\GNU\GNUPG>

    Gpg: unchanged: 1

    C:\Program files\GNU\GNUPG>

    C:\Program files\GNU\GNUPG>gpg- -gen-key kalyani

    Gpg(GNUPG)1.4.9

    Copyright(c) 2008 Free software foundation, Inc

    License GPL v3+: GNU GPL version 3 or laterhttp://gnu.org/license/gpl.html

    This is free software: you are free to change and redistribute it.

    There is no warranty to the extent permitted by law.

    Secret key is available

    Pub 1024D/5BC4A08F: created: 2009-04-01 expires:2009-04-10 usage: sc trust: ultimate

    validity: ultimate.

    Sub 1024g/1C02598B created: 2009-04-01 expires:2009-04-10 usage: E[ultimate]

    1) kalyani(hello world)[email protected]

    Please decide how far you trust this user to correctly verify other users keys.

    1 = I dont know or wont say0

    2 = I do not trust

    3 = I trust marginally

    mailto:[email protected]://gnu.org/license/gpl.htmlmailto:[email protected]:[email protected]://gnu.org/license/gpl.htmlmailto:[email protected]
  • 7/28/2019 Complete Lab Programs

    26/71

    4 = I trust fully

    5 = I trust ultimately

    m = back to main menu

    Your decision ? 4

    Pub 1024D/5BC4A08F: created: 2009-04-01 expires:2009-04-10 usage: sc trust: ultimate

    validity: ultimate.

    Sub 1024g/1C02598B created: 2009-04-01 expires:2009-04-10 usage: E[ultimate]

    2) kalyani(hello world)[email protected]

    Please note that the shown key validity is not necessarily correct.

    Command> ^c

    C:\Program files\GNU\GNUPG>gpg- -recipient kalyani- - output

    author.pgp - - encrypt author.txt

    gpg: checking the trustdb.

    gpg: marginal(s) nded, 1 complete (s) needed, PGP trust model.

    gpg: depth:0 valid:5 signed:0 trust:0-, 0q, 0n, 0m, 0f, 5u.

    gpg: next trustdb ckeckdue at 2009-04-10

    gpg: 1C02598B: There is no assurance this key belongs to the named user

    Pub 1024g/1C02598B created: 2009-04-01 kalyani(hello world 2)[email protected]

    Primary key finger print: C1F1 4B6C 87DB 4464 7253 790F 9F1C 5A8E 5BC4 A08F

    Subkey fingerprint : 8674 C498 3928 D581 C72C CF3A 55F1 9E5A 1C02 5928B

    mailto:[email protected]:[email protected]:[email protected]:[email protected]
  • 7/28/2019 Complete Lab Programs

    27/71

    Its not certain that the key belongs to the person named in the user id. If you *really* know what

    you are doing, you may answer the next question with yes.

    Use this key anyway?(Y/N)Y.

    gpg: cant open author.text: No such file or directory.

    gpg: author.txt encryption failed: file open error.

    EXPERIMENT NUMBER 5:

    Performance evalution of various cryptographic algorithms

    # include

    # include

  • 7/28/2019 Complete Lab Programs

    28/71

    #include

    # define max 50

    char

    a[26]={a,b,c,d,e,f,g,h,i,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z};

    void main()

    {

    int I,j,r1,r2,c1,c2,k,n,flg[26]={0};

    char t,tmp,txt[max],pt[max],key[max],mt[5][5],cp[max];

    clrscr();

    printf(enter the plain text);

    gets(txt);

    printf(enter the key);

    scanf(%s,key);

    for(i=0;j=0;i

  • 7/28/2019 Complete Lab Programs

    29/71

    pt[j]=\0;

    for(i=0;i

  • 7/28/2019 Complete Lab Programs

    30/71

    {

    for(i=0;j=0;k=0;k

  • 7/28/2019 Complete Lab Programs

    31/71

    flag[n]=1;

    }

    }

    for(k=0;i

  • 7/28/2019 Complete Lab Programs

    32/71

    printf(%c,mt[i][j]);

    printf(\n);

    }

    printf(encryption \n);

    for(i=0;i

  • 7/28/2019 Complete Lab Programs

    33/71

    }

    if(r1==r2)

    {

    c1++;

    if(c1==5)

    c1=0;

    cp[i]=mt[r1][c1];

    c2++;

    if(c2==5)

    cp[i+1]=mt[r2][c2];

    }

    else if(c1==c2)

    {

    r1++;

    if(r1==5)

    r1=0;

    cp[i]=mt[r1][c1];

    r2++;

    if(r2==5)

    r2=0;

  • 7/28/2019 Complete Lab Programs

    34/71

    cp[i+1]=mt[r2][c2];

    }

    else

    {

    cp[i]=mt[r1][c1];

    cp[i+1]=mt[r2][c2];

    }

    }

    cp[i]=\0;

    printf(\n encrypted text is:);

    for(i=0;i

  • 7/28/2019 Complete Lab Programs

    35/71

    o/p

    matrix is : monar

    chu bcl

    cfgik

    iqst

    uvwxz

    Encryption:

    The Encryption cipher text is:ibsupmna

    EXPERIMENT NUMBER 6:

    Performance Evaluation of Various Cryptography Algorithms

    #include

    #include

  • 7/28/2019 Complete Lab Programs

    36/71

    #include

    #define MAX 50

    char a[26] = {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,

    p,q,r,s,t,u,v,w,x,y,z};

    void main()

    {

    int i,j,r1,r2,c1,c2,k,n,flg[26] = {0};

    char t, tmp, txt[max], pt[max], key[max], mt[5][5], cp[max];

    clrscr();

    printf(enter the plain text:);

    gets(txt);

    printf(enter the key:);

    scanf(%s,key);

    for(i=0;j=0;i

  • 7/28/2019 Complete Lab Programs

    37/71

  • 7/28/2019 Complete Lab Programs

    38/71

    else

    {

    for(i=0;j=0;k=0;k

  • 7/28/2019 Complete Lab Programs

    39/71

  • 7/28/2019 Complete Lab Programs

    40/71

    flg[k]=1;

    k++;

    if(k==9)

    k++;

    }

    j=0;

    }

    printf("\n matrix is : \n");

    for(i=0;i

  • 7/28/2019 Complete Lab Programs

    41/71

    for(k=0;k

  • 7/28/2019 Complete Lab Programs

    42/71

    c2=0;

    cp[i+1]=mt[r2][c2];

    }

    elseif(c1==c2)

    {

    r1++;

    if(r1==5)

    r1=0;

    cp[i]=mt[r1][c1];

    r2++;

    if(r2==5)

    r2=0;

    cp[i+1]=mt[r2][c2];

    }

    else

    {

    cp[i]=mt[r1][c1];

    cp[i+1]=mt[r2][c2];

    }

    }

  • 7/28/2019 Complete Lab Programs

    43/71

    cp[i]='\0';

    printf("\n encrypted text is :");

    for(I=0;I

  • 7/28/2019 Complete Lab Programs

    44/71

    EXPERIMENT NUMBER 7:

    Understanding the buffer overflow and format string attacks

    #include

    #include

  • 7/28/2019 Complete Lab Programs

    45/71

    #include

    void main()

    {

    int i=0,j=0,k=0;

    char str[100],buf[10]={'\0'},xtra[50]={'\0'};

    //clrscr();

    printf("\nenter the string less than 10 char\n");

    scanf("%s",str);

    if(strlen(str)

  • 7/28/2019 Complete Lab Programs

    46/71

    k++;

    }

    printf("overflow data is%s\n",xtra);

    }

    getch();

    }

    TEST DATA

    Input: enter the string less than 10 char

    abcdefgh

    Output: the given input doesnot result in overflow

    Input: enter the string less than 10 char

    abcdefghijklm

    Output: data in buffer is abcdefghij

    overflow data isk

    EXPERIMENT NUMBER 8:

    String Attacks

    #include

    #include

  • 7/28/2019 Complete Lab Programs

    47/71

  • 7/28/2019 Complete Lab Programs

    48/71

    is commonly used for security audits, many systems and networks administrators find it useful

    for routine tasks such as network inventory, managing service upgrade schedules and monitoring

    hosts.

    Scans availability through NMAP

    Scan Type Option

    TCP connect()

    Scan-sT

    The most basic form of scanning this opens a

    connection to every potentially interesting port

    on the target machine.

    TCP SYN Scan -sS

    The half-open scan .this scan sends a TCP

    SYN Packet as through it is trying to open the

    Connection. If it receives a SYN-ACK

    response, it sends an immediate RST to shut

    down the connection.

    Stealth FIN -sFThis scan attempts to pass through packet

    filters by sending a TCP FIN packet.

    X-Mas Tree -sX

    This scan attempts to pass through packet

    filters by sending a packet with out any flags

    turned on. Packet with FIN,URG and PUSH

    flags etc.

    NULL -sN

    This scan attempts to pass through packet

    filters by sending a packet without any flags

    turned on.

    Ping -sP

    This limits the scan to only conducting a ping

    sweep to look for connected systems. It does

    not do port scans.

    USP scan -sUThis sends 0 byte USP packets to each port on

    the target machine(s).

    ACK scan sA

    This scan used to help check packet filters an

    ACK packet with random acknowledgement

    and sequence numbers is sent. If nothing is

    returned the port is marked as filtered.

  • 7/28/2019 Complete Lab Programs

    49/71

    List scan -sL Simply lists targets to scan.

    FTP bounce scan -b

    This scan relives a historical foible of FTP

    servers. Older FTP servers were able to srve

    bounced FTP sessions; this is, they connected

    to another host to deliver data to you.

    By providing a relay host in the format

    Username; password @ server: port, you can

    use this FTP bounce (mis) feature to scan port

    that might otherwise be protected.

    In addition to the types of scans that NMAP can run a number of options modify its behavior.

    These options include timing, target identification; o/p and others. Some of the more useful

    options are shown in following table.

    Option Description

    -PO Tells NMAP not to ping hosts before scanning

    -fCauses NMAP to fragment its scanning packets, making it more

    difficult to block the scan with packet filters.

    -vputs NMAP into verbose mode causing it to display much more

    information about what its doing.

    ON Writes o/p into a human readable log file.

    OM Writes o/p to a machine-parseable log file.

    --resume Resumes an incomplete scan from a log file.

    -iLCauses NMAP to read I/P from a log file instead of really scanning

    a host.

    -g Allows you to define the port NMAP uses as its source port.

    -p

    Allows you to define the range of ports NMAP will scan. If no

    range is given, NMAP will scan all the ports listed in its own

    services file. A range of ports can be given in the following format:-

    p20-30, 79, 6000-6010.

    Operating System Detection:

  • 7/28/2019 Complete Lab Programs

    50/71

    Allows the user to use TCP/IP finger printing to determine the operating system of the

    remote host NMAP command line prompt:

    C:\nmap>nmap-0 www.hackingmobilephones.com

    Is nmap good or Evil?

    A tool as powerful as namp can be a double-edged sword. At least one internet-

    related reference to nmap describes it as a hacking tool, and technology purists who dont

    consider the word hack to be a four letter word would certainty agree with this description. It is

    unformatting that the term hacker has been used incorrectly so often in main stream society.

    These uninformed connotations of hacking have overshadowed the original meaning of the wordand altered it in horribly negative ways true hacking is about the pursuit of technology, not about

    illegal or inappropriate technology subversions.

    The bad guys are already using nmap for reconnaissance, because a single scan tells

    you a lot about the open and windows in a computers house. What the bad guys do once they

    have this information is why they are called bad guys.

    The good guys are using nmap to make their network safer. The network management

    team uses nmap to identify unknown IP address that appears in reports or in a network analysis

    trace. The security team uses nmap to scan the extent of a spyware infestation.

    Typical uses of NMAP:

    Auditing the security of a computer by identifying the network connections which can be

    made to it.

    Identifying open ports on a target computer in preparation for auditing.

    Network inventory, maintenance and asset management.

    Auditing the security of a network, by identifying unexpected new servers.

    http://www.hackingmobilephones.com/http://www.hackingmobilephones.com/
  • 7/28/2019 Complete Lab Programs

    51/71

    EXPERIMENT NUMBER 10:

    RSA Algorithm

    #include

    #include

    #include

    void main()

    {

    int p,q,fi,n,e,o,i,d;

  • 7/28/2019 Complete Lab Programs

    52/71

    int temp[10],j=0;

    long int c,m,t1,t2;

    clrscr();

    printf(enter any 2 different prime nos);

    scanf(%d%d,&p,&q);

    n=p*q;

    fi=(p-1)*(q-1);

    for(i=2;i

  • 7/28/2019 Complete Lab Programs

    53/71

    scanf(%d,&e);

    }

    printf(/n);

    for(i=2;;i++)

    {

    if((i*e)%fi==1)

    goto assign;

    }

    assign:d=i;

    printf(/n public key ku:);

    printf({);

    printf(%d,e);

    printf(,);

    printf(%d,n);

    printf(});

    printf(/n);

    printf(/n private key kr:);

    printf({);

    printf(%d,d);

    printf(,);

  • 7/28/2019 Complete Lab Programs

    54/71

    printf(%d,n);

    printf(});

    printf(/n);

    printf(/n enter plain text);

    scanf(%id,&m);

    t1=pow(m,e);

    c=t1%n;

    printf(/n cipher text:);

    printf(%id,c);

    t2=pow(c,d);

    printf(/n);

    m=t2%n;

    printf(/n plain text:);

    printf(%id,m);

    getch();

    }

  • 7/28/2019 Complete Lab Programs

    55/71

    TEST DATA:

    Enter any 2 different prime nos: 3 5

    Select any one of the below values

    3567

    1

    Public key ku: {1,15}

    Private key kp: {9,15}

    Enter plain text: 12

    Cipher text 4d

    Plain text 4d

    EXPERIMENT NUMBER 11

    Diffie Hellman Key Exchange Algorithm

    #include

    #include

    #include

    void main()

    {

    int q,alp,xa,xb,ka,kb;

  • 7/28/2019 Complete Lab Programs

    56/71

  • 7/28/2019 Complete Lab Programs

    57/71

    }

    TEST DATA

    enter the values of q & alpha: 2 2

    enter the private keys for A & B: 4 2

    the keys ka and kb are 00

    keys are exchanged successfully

    EXPERIMENT NUMBER 12

    DES Algorithm

    #include

    #include

    main()

    {

    char p[100];

  • 7/28/2019 Complete Lab Programs

    58/71

    char

    a[26]={a,b,c,d,e,f,g,h,I,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z

    };

    char b[25];

    int k,I,j,h,c,flag,l;

    clrscr();

    printf(enter the no of charcters in the plain text);

    scanf(%d,&h);

    printf(enter the key value range between 0 and 25);

    scanf(%d,&k);

    printf(enter the values for plain text);

    for(i=0;i

  • 7/28/2019 Complete Lab Programs

    59/71

    for(j=k;j

  • 7/28/2019 Complete Lab Programs

    60/71

    getch();

    }

    TEST DATA

    enter the no of charcters in the plain text:7

    enter the key value range between 0 and 25:3

    enter the values for plain text:vignesh

    the cipher text is: yliqhvk

    EXPERIMENT NUMBER 13

    Polyalphabetic Cipher

    #include

    #include

    main()

    {

    char p[100];

  • 7/28/2019 Complete Lab Programs

    61/71

    char

    a[26]={a,b,c,d,e,f,g,h,I,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z

    };

    char b[26],y[26]={h,a,I};

    int k[10],i,j,h,c,z,l,m,n[10],v[10],s,g;

    clrscr();

    printf(enter the no of characters in the plain text);

    scanf(%d,&h);

    printf(enter the value for plain text);

    for(i=0;i

  • 7/28/2019 Complete Lab Programs

    62/71

    c++;

    }

    }

    }

    c=0;

    for(j=0;j

  • 7/28/2019 Complete Lab Programs

    63/71

    i++;

    }

    for(i=0;i

  • 7/28/2019 Complete Lab Programs

    64/71

    getch();

    }

    TEST DATA

    enter the no of charcters in the plain text:9

    enter the values for plain text:ganapathi

    the cipher text is: navhpibhq

    EXPERIMENT NUMBER 14

    Single Columnar Cipher

    #include

    #include

    main()

    {

    int i,h,j=0,k,a[5],m,x;

  • 7/28/2019 Complete Lab Programs

    65/71

    char p[100],c[200],v[100],u[100];

    clrscr();

    printf(enter the length of plain text and it should be greater than 5);

    scanf(%d,&h);

    printf(enter the plain text and the number of char should be greater than 5);

    for(i=0;i

  • 7/28/2019 Complete Lab Programs

    66/71

    m=i;

    j=2;

    for(i=0;j

  • 7/28/2019 Complete Lab Programs

    67/71

    if(a[j]==3)

    {

    for(i=0;i

  • 7/28/2019 Complete Lab Programs

    68/71

    char

    a[100]={a,b,c,d,e,f,g,h,I,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z

    };

    int I,j,h,k[26],n[26],c,r[28],v;

    clrscr();

    printf(enter the no of charcters in the plain text);

    scanf(%d,&h);

    printf(enter the value for plain text);

    for(i=0;i

  • 7/28/2019 Complete Lab Programs

    69/71

    c++;

    }

    }

    }

    c=0;

    for(j=0;j

  • 7/28/2019 Complete Lab Programs

    70/71

    printf(the cipher text is);

    for(i=0;i25)

    {

    v=v-26;

    printf(%c,a[v]);

    }

    else

    {

    printf(%c,a[v]);

    }

    }

    getch();

    }

  • 7/28/2019 Complete Lab Programs

    71/71

    TEST DATA

    enter the no of charcters in the plain text:9

    enter the values for plain text:how are you

    enter the one time paid:ncbtzqarx

    the cipher text is: uqxtquyfr