From 6d1e7df45edff5b3867e689f8d4a4b33d9ccf49c Mon Sep 17 00:00:00 2001 From: Nakul Suresh Date: Thu, 28 Jun 2018 17:19:22 +0400 Subject: [PATCH 1/6] Added crypto assignment phase 1 --- .../Nakul/nakul-caesar_ciphertext.txt | 2 + .../Nakul/nakul-caesar_encryption.c | 33 ++++++++++++ .../Nakul/nakul-substitution_ciphertext.txt | 2 + .../Nakul/nakul-substitution_encryption.c | 34 ++++++++++++ .../Nakul/nakul-vigener_ciphertext.txt | 1 + .../Nakul/nakul-vigener_encryption.c | 53 +++++++++++++++++++ .../Nakul/nakul-vigener_keyfile.txt | 1 + 7 files changed, 126 insertions(+) create mode 100644 RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_ciphertext.txt create mode 100644 RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_encryption.c create mode 100644 RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_ciphertext.txt create mode 100644 RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_encryption.c create mode 100644 RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_ciphertext.txt create mode 100644 RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_encryption.c create mode 100644 RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_keyfile.txt diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_ciphertext.txt b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_ciphertext.txt new file mode 100644 index 0000000..83f1612 --- /dev/null +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_ciphertext.txt @@ -0,0 +1,2 @@ +d gudjrqeruq lv d pruwdo pdq ru zrpdq eruq zlwk wkh vrxo ri d gudjrq.lw hqdeohv wkhp wr xvh wkh gudjrq'v delolwb wr devrue d vodlq gudjrq'v vrxo wr uhfhlyh nqrzohgjh ri wkh wkx'xp, udwkhu wkdq kdylqj wr ohduq wkurxjk sudfwlfh.vw. dohvvld zdv wkh iluvw shuvrq wr eh dvvrfldwhg zlwk wkh wlwoh gudjrqeruq.vkh lv eholhyhg wr kdyh jdlqhg wkh eorrg ri d gudjrq diwhu pdnlqj d fryhqdqw zlwk dndwrvk wr vhdo wkh jdwhv ri reolylrq. vlqfh wkhq, wkhuh kdyh ehhq pdqb wdohv ri khurhv ri wkh gudjrqv eorrg zkr zrxog nloo gudjrqv dqg vwhdo wkhlu srzhu. wkh delolwb wr devrue gudjrq vrxov fdph iluvw wr wkh gudjrq sulhvw pluddn. diwhuzdugv, doo nqrzq gudjrqeruqv frxog ohduq srzhuixo vkrxwv pxfk txlfnhu wkdq rwkhu pruwdov, zkr uhtxluh bhduv ri phglwdwlrq wr pdvwhu wkhp. + \ No newline at end of file diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_encryption.c b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_encryption.c new file mode 100644 index 0000000..b8badd3 --- /dev/null +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_encryption.c @@ -0,0 +1,33 @@ + + #include +#include +#include +void main(){ +char ct[1000],pt[1000]; +FILE *f1; +f1=fopen("nakul-caesar_message.txt","r"); +if(f1==NULL) + {printf("can't access file\n"); + exit(0); + } +fgets(pt,1000,f1); +fclose(f1); +int i; +for(i=0;pt[i]!='\0';i++) + {if(pt[i]>=97&&pt[i]<=122) + { pt[i]-=97; + ct[i]=(pt[i]+3)%26 +97; + } + else + ct[i]=pt[i]; + } +FILE *f2; +f2=fopen("nakul-caesar_ciphertext.txt","w"); +if(f2==NULL) + {printf("can't access file\n"); + exit(0); + } +fputs(ct,f2); +fclose(f2); +} + diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_ciphertext.txt b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_ciphertext.txt new file mode 100644 index 0000000..d6708e4 --- /dev/null +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_ciphertext.txt @@ -0,0 +1,2 @@ +bism ug pmizb epmv gwc ow, itbpwcop qb lwmav'b twws tqsm ivgbpqvo bw um. +dÄæÿ \ No newline at end of file diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_encryption.c b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_encryption.c new file mode 100644 index 0000000..8060316 --- /dev/null +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_encryption.c @@ -0,0 +1,34 @@ +#include +#include +#include +void main(){ +char ct[1000],pt[1000]; +FILE *f1; +f1=fopen("nakul-substitution_message.txt","r"); +if(f1==NULL) + {printf("can't access file\n"); + exit(0); + } +fgets(pt,1000,f1); +fclose(f1); + +int i; +for(i=0;pt[i]!='\0';i++) + {if(pt[i]>=97&&pt[i]<=122) + { pt[i]-=97; + ct[i]=(pt[i]+8)%26 +97; + } + else + ct[i]=pt[i]; + } + + +FILE *f2; +f2=fopen("nakul-substitution_ciphertext.txt","w"); +if(f2==NULL) + {printf("can't access file\n"); + exit(0); + } +fputs(ct,f2); +fclose(f2); +} diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_ciphertext.txt b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_ciphertext.txt new file mode 100644 index 0000000..a06e1a4 --- /dev/null +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_ciphertext.txt @@ -0,0 +1 @@ +dvjrny aeP macwsg mKvv r qrgmZcs updkxwPgk cttx s] jolnv emSkug hvbei yhttswgz Ogyued hy _kz ylg-ui\p syzk. a_kse dhtrmKi aczbx l\ oojeg t Mcytp kaxv\ oe xsxmw vvdu qatz\b, r mhnr^ zlrnyxk Jcu nsc giSgy cpooxw jps scnli cud msvhq\u bfuovd'P vncj ykm\pk. ss tgQwhlcj vtv\u ffc mhh[, dvddbmi uhyzyu hx_gywzds. l\ kiuy'm aXpa kzrw xL sergs amJ, ffc yxeO vf wcgxp`plsj, tgh uhbfeozxh jps ccvd Lrlrr. uhnXer rwgh f\ipnj hh hXvl ytg tk\pa, afbgg\uz tlfhecK, ie og i]hvrk hh rLv bv oehr\, acevhnk_ ahvtf kiIcaifygabt kz ry hg-Xihie-cyy-Xihie cgx. jl rwgh qRua upoe a`vo dc. iiXpbtsfhmxv, dhfx tewL oau o mz uoon wg x_g 90d vtpIgk dc. iiXpbtsfhmxv'u hffgx, Tjpcy phceZm cclwfl Zqwivo ahvPku' lfhnr['z gcsfbw\, tytg twPwtpktcg xRtus zim xL ie nckkiZv aj hax Tqykzyu mmQnl nlg nrQkalvo ahvPku' lfhnr[ rnfnyhyj, hs csoxeIgk zy lxePqu 4. Dni vv kswl l\ joedwwxvP tr. dxtrRviukesk e tpvrw, pl\tlaj hax Icatvc bl Zqusklbmec gueirsmbg cud nvxxv]ws rccngh dvjrny, gLpziupfbgk jpm l ykm\pk, hvbvl lbsk oggsVu bfuovd \ No newline at end of file diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_encryption.c b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_encryption.c new file mode 100644 index 0000000..0fcf1c2 --- /dev/null +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_encryption.c @@ -0,0 +1,53 @@ +#include +#include +#include +void main(){ +char ct[1000],pt[1000],key[1000],k[100]; +FILE *f1,*fp,*f2; + +f1=fopen("nakul-vigener_message.txt","r"); +if(f1==NULL) + {printf("can't access file\n"); + exit(0); + } +fgets(pt,1000,f1); +fclose(f1); + + +fp=fopen("nakul-vigener_keyfile.txt","r"); +if(fp==NULL) + {printf("can't access file\n"); + exit(0); + } +fgets(k,1000,fp); +fclose(fp); + + +int i,j,n=strlen(k); +for(i=0,j=0;i=97&&pt[j]<=122) + { pt[j]-=97; + key[j]-=97; + ct[j]=(pt[j]+key[j])%26 +97; + } + else + ct[j]=pt[j]; + } + + +f2=fopen("nakul-vigener_ciphertext.txt","w"); +if(f2==NULL) + {printf("can't access file\n"); + exit(0); + } +fputs(ct,f2); +fclose(f2); +} diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_keyfile.txt b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_keyfile.txt new file mode 100644 index 0000000..eeaca8b --- /dev/null +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_keyfile.txt @@ -0,0 +1 @@ +charlotte From e01b896965bc5cb1269614e6e3464379b20471b5 Mon Sep 17 00:00:00 2001 From: Nakul Suresh Date: Thu, 28 Jun 2018 18:18:18 +0400 Subject: [PATCH 2/6] Modified vigener encryption algorithm --- .../Nakul/nakul-vigener_ciphertext.txt | 2 +- .../Nakul/nakul-vigener_encryption.c | 26 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_ciphertext.txt b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_ciphertext.txt index a06e1a4..ef995a7 100644 --- a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_ciphertext.txt +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_ciphertext.txt @@ -1 +1 @@ -dvjrny aeP macwsg mKvv r qrgmZcs updkxwPgk cttx s] jolnv emSkug hvbei yhttswgz Ogyued hy _kz ylg-ui\p syzk. a_kse dhtrmKi aczbx l\ oojeg t Mcytp kaxv\ oe xsxmw vvdu qatz\b, r mhnr^ zlrnyxk Jcu nsc giSgy cpooxw jps scnli cud msvhq\u bfuovd'P vncj ykm\pk. ss tgQwhlcj vtv\u ffc mhh[, dvddbmi uhyzyu hx_gywzds. l\ kiuy'm aXpa kzrw xL sergs amJ, ffc yxeO vf wcgxp`plsj, tgh uhbfeozxh jps ccvd Lrlrr. uhnXer rwgh f\ipnj hh hXvl ytg tk\pa, afbgg\uz tlfhecK, ie og i]hvrk hh rLv bv oehr\, acevhnk_ ahvtf kiIcaifygabt kz ry hg-Xihie-cyy-Xihie cgx. jl rwgh qRua upoe a`vo dc. iiXpbtsfhmxv, dhfx tewL oau o mz uoon wg x_g 90d vtpIgk dc. iiXpbtsfhmxv'u hffgx, Tjpcy phceZm cclwfl Zqwivo ahvPku' lfhnr['z gcsfbw\, tytg twPwtpktcg xRtus zim xL ie nckkiZv aj hax Tqykzyu mmQnl nlg nrQkalvo ahvPku' lfhnr[ rnfnyhyj, hs csoxeIgk zy lxePqu 4. Dni vv kswl l\ joedwwxvP tr. dxtrRviukesk e tpvrw, pl\tlaj hax Icatvc bl Zqusklbmec gueirsmbg cud nvxxv]ws rccngh dvjrny, gLpziupfbgk jpm l ykm\pk, hvbvl lbsk oggsVu bfuovd \ No newline at end of file +dvjrny aeu frwzxg kutf o vcppcrw wxttlsjpr emhl fq vhyeo ctjbgk dhzws pevjhzyu kitbnj cy lkz ylg-uigu jscp. yoicp lmeapnx oehrg hv vhlxu a aokmc dhvcs ai teveg msfk tsooxd, a jcngk zlrnyxk ohn hvh rgcei zxtzgz ytg aswze lbw fgjodpg uslhcb'g hrnf wcwxgh. hv ovmycslp qtkiu ffc mhhf, upgibxg srjwgz qahvckbli. hv rbwr'a nlbm xqkd ec eicce swf, hvr qstk qm czbxemplsj, tgh zaszhtzif hzd khgm ogpft. diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_encryption.c b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_encryption.c index 0fcf1c2..1a0b336 100644 --- a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_encryption.c +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_encryption.c @@ -2,7 +2,7 @@ #include #include void main(){ -char ct[1000],pt[1000],key[1000],k[100]; +char ct[1000],pt[1000],key[1000],k[1000]; FILE *f1,*fp,*f2; f1=fopen("nakul-vigener_message.txt","r"); @@ -11,7 +11,8 @@ if(f1==NULL) exit(0); } fgets(pt,1000,f1); -fclose(f1); +fseek(f1,0,2); +long int len=ftell(f1); fp=fopen("nakul-vigener_keyfile.txt","r"); @@ -20,16 +21,15 @@ if(fp==NULL) exit(0); } fgets(k,1000,fp); -fclose(fp); - - -int i,j,n=strlen(k); -for(i=0,j=0;i Date: Thu, 28 Jun 2018 18:59:22 +0400 Subject: [PATCH 3/6] Added UNIX assignment 1 --- UNIX/Nakul/assignment1.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 UNIX/Nakul/assignment1.sh diff --git a/UNIX/Nakul/assignment1.sh b/UNIX/Nakul/assignment1.sh new file mode 100755 index 0000000..9e2ff28 --- /dev/null +++ b/UNIX/Nakul/assignment1.sh @@ -0,0 +1,19 @@ +#!/bin/bash +echo enter 3 nos +read a b c +if [ $a -gt $b ] + then + if [ $a -gt $c ] + then + echo $a is the greatest + else + echo $c is the greatest + fi +elif [ $b -gt $c ] + then + echo $b is the greatest + else + echo $c is the greatest +fi +d=$((a+b+c)) +echo sum= $d From e4620368f5d89200ee6311932f9ccf978f273830 Mon Sep 17 00:00:00 2001 From: Nakul Suresh Date: Sat, 30 Jun 2018 13:33:43 +0400 Subject: [PATCH 4/6] Modified substitution encryption --- .../Nakul/nakul-substitution_ciphertext.txt | 3 +-- .../Nakul/nakul-substitution_encryption.c | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_ciphertext.txt b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_ciphertext.txt index d6708e4..5b87cf0 100644 --- a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_ciphertext.txt +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_ciphertext.txt @@ -1,2 +1 @@ -bism ug pmizb epmv gwc ow, itbpwcop qb lwmav'b twws tqsm ivgbpqvo bw um. -dÄæÿ \ No newline at end of file +ktctkotl diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_encryption.c b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_encryption.c index 8060316..0b8f878 100644 --- a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_encryption.c +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_encryption.c @@ -2,7 +2,7 @@ #include #include void main(){ -char ct[1000],pt[1000]; +char ct[1000],pt[1000],k[26]; FILE *f1; f1=fopen("nakul-substitution_message.txt","r"); if(f1==NULL) @@ -12,16 +12,24 @@ if(f1==NULL) fgets(pt,1000,f1); fclose(f1); +FILE *fk; +fk=fopen("nakul-substitution_Key.txt","r"); +if(fk==NULL) + {printf("can't access file\n"); + exit(0); + } +fgets(k,26,fk); +fclose(fk); + int i; for(i=0;pt[i]!='\0';i++) - {if(pt[i]>=97&&pt[i]<=122) - { pt[i]-=97; - ct[i]=(pt[i]+8)%26 +97; - } - else - ct[i]=pt[i]; - } - +{ if(pt[i]>=97&&pt[i]<=122) + { int a =pt[i]-97; + ct[i]=k[a]; + } + else + ct[i]=pt[i]; +} FILE *f2; f2=fopen("nakul-substitution_ciphertext.txt","w"); From 186b3f7b2f975cd6b92f0a93fd4c8b3668f73048 Mon Sep 17 00:00:00 2001 From: Nakul Suresh Date: Sun, 1 Jul 2018 16:58:02 +0400 Subject: [PATCH 5/6] Indented code for easy readability --- .../Nakul/nakul-caesar_encryption.c | 47 ++++++++----- .../Nakul/nakul-substitution_encryption.c | 52 ++++++++------ .../Nakul/nakul-vigener_encryption.c | 69 +++++++++++-------- 3 files changed, 97 insertions(+), 71 deletions(-) diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_encryption.c b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_encryption.c index b8badd3..8997716 100644 --- a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_encryption.c +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_encryption.c @@ -1,33 +1,42 @@ - - #include +#include #include #include void main(){ char ct[1000],pt[1000]; + FILE *f1; -f1=fopen("nakul-caesar_message.txt","r"); -if(f1==NULL) - {printf("can't access file\n"); - exit(0); - } +f1 = fopen("nakul-caesar_message.txt","r"); + if(f1==NULL) + { + printf("can't access file\n"); + exit(0); + } fgets(pt,1000,f1); fclose(f1); + + int i; -for(i=0;pt[i]!='\0';i++) - {if(pt[i]>=97&&pt[i]<=122) - { pt[i]-=97; - ct[i]=(pt[i]+3)%26 +97; - } - else - ct[i]=pt[i]; - } +for(i = 0; pt[i] != '\0'; i++) + { + if(pt[i] >= 97 && pt[i] <= 122) + { + pt[i] -= 97; + ct[i] = (pt[i] + 3)%26 +97; + } + else + ct[i] = pt[i]; + } + + FILE *f2; f2=fopen("nakul-caesar_ciphertext.txt","w"); -if(f2==NULL) - {printf("can't access file\n"); - exit(0); - } + if(f2==NULL) + { + printf("can't access file\n"); + exit(0); + } fputs(ct,f2); fclose(f2); + } diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_encryption.c b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_encryption.c index 0b8f878..5323291 100644 --- a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_encryption.c +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_encryption.c @@ -4,39 +4,47 @@ void main(){ char ct[1000],pt[1000],k[26]; FILE *f1; -f1=fopen("nakul-substitution_message.txt","r"); -if(f1==NULL) - {printf("can't access file\n"); - exit(0); - } +f1 = fopen("nakul-substitution_message.txt","r"); + if(f1==NULL) + { + printf("can't access file\n"); + exit(0); + } fgets(pt,1000,f1); fclose(f1); FILE *fk; -fk=fopen("nakul-substitution_Key.txt","r"); -if(fk==NULL) - {printf("can't access file\n"); - exit(0); - } +fk = fopen("nakul-substitution_Key.txt","r"); + if(fk==NULL) + { + printf("can't access file\n"); + exit(0); + } fgets(k,26,fk); fclose(fk); + int i; -for(i=0;pt[i]!='\0';i++) -{ if(pt[i]>=97&&pt[i]<=122) - { int a =pt[i]-97; - ct[i]=k[a]; +for(i = 0; pt[i] != '\0'; i++) + { + if(pt[i] >= 97 && pt[i] <= 122) + { + int a = pt[i]-97; + ct[i] = k[a]; + } + else + ct[i] = pt[i]; } - else - ct[i]=pt[i]; -} + FILE *f2; -f2=fopen("nakul-substitution_ciphertext.txt","w"); -if(f2==NULL) - {printf("can't access file\n"); - exit(0); - } +f2 = fopen("nakul-substitution_ciphertext.txt","w"); + if(f2==NULL) + { + printf("can't access file\n"); + exit(0); + } fputs(ct,f2); fclose(f2); + } diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_encryption.c b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_encryption.c index 1a0b336..c7f398f 100644 --- a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_encryption.c +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_encryption.c @@ -5,51 +5,60 @@ void main(){ char ct[1000],pt[1000],key[1000],k[1000]; FILE *f1,*fp,*f2; -f1=fopen("nakul-vigener_message.txt","r"); -if(f1==NULL) - {printf("can't access file\n"); - exit(0); - } +f1 = fopen("nakul-vigener_message.txt","r"); + if(f1==NULL) + { + printf("can't access file\n"); + exit(0); + } fgets(pt,1000,f1); fseek(f1,0,2); -long int len=ftell(f1); +long int len = ftell(f1); fp=fopen("nakul-vigener_keyfile.txt","r"); if(fp==NULL) - {printf("can't access file\n"); - exit(0); - } + { + printf("can't access file\n"); + exit(0); + } fgets(k,1000,fp); + int i,j; -int key_length=strlen(k); -for(i=0,j=0;i=97&&pt[j]<=122) - { pt[j]-=97; - key[j]-=97; - ct[j]=(pt[j]+key[j])%26 +97; + + +for(j = 0; pt[j] != '\0' ; j++) + { + if(pt[j] >= 97 && pt[j] <= 122) + { + pt[j] -= 97; + key[j] -=97; + ct[j] = (pt[j] + key[j]) %26 +97; + } + else + ct[j]=pt[j]; } - else - ct[j]=pt[j]; - } -f2=fopen("nakul-vigener_ciphertext.txt","w"); -if(f2==NULL) - {printf("can't access file\n"); - exit(0); - } +f2 = fopen("nakul-vigener_ciphertext.txt","w"); + if(f2==NULL) + { + printf("can't access file\n"); + exit(0); + } fputs(ct,f2); + fclose(fp); fclose(f2); fclose(f1); + } From d2b119190233aa630c8ee7775e8161cf7fedf40d Mon Sep 17 00:00:00 2001 From: Nakul Suresh Date: Tue, 24 Jul 2018 19:14:48 +0530 Subject: [PATCH 6/6] added decryption files --- .../Nakul/nakul-caesar_decrypted.txt | 2 + .../Nakul/nakul-caesar_decryption.c | 32 +++++++++++ .../Nakul/nakul-substitution_decrypted.txt | 2 + .../Nakul/nakul-substitution_decryption.c | 49 +++++++++++++++++ .../Nakul/nakul-vigener_decrypted.txt | 1 + .../Nakul/nakul-vigener_decryption.c | 55 +++++++++++++++++++ 6 files changed, 141 insertions(+) create mode 100644 RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_decrypted.txt create mode 100644 RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_decryption.c create mode 100644 RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_decrypted.txt create mode 100644 RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_decryption.c create mode 100644 RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_decrypted.txt create mode 100644 RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_decryption.c diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_decrypted.txt b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_decrypted.txt new file mode 100644 index 0000000..d888e4d --- /dev/null +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_decrypted.txt @@ -0,0 +1,2 @@ +modern cryptography is heavily based on mathematical theory and computer science practice cryptographic algorithms are designed around computational hardness assumptions making such algorithms hard to break in practice by any adversary it is theoretically possible to break such a system but it is infeasible to do so by any known practical means these schemes are therefore termed computationally secure theoretical advances eg improvements in integer factorization algorithms and faster computing technology require these solutions to be continually adapted there exist information0theoretically secure schemes that probably cannot be broken even with unlimited computing power an example is the one time pad but these schemes are more difficult to implement than the best theoretically breakable but computationally secure mechanisms + \ No newline at end of file diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_decryption.c b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_decryption.c new file mode 100644 index 0000000..90afe4e --- /dev/null +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-caesar_decryption.c @@ -0,0 +1,32 @@ +#include +#include +#include +void main(){ +char ct[1000],pt[1000]; +FILE *f1; +f1=fopen("nakul-caesar_encoded.txt","r"); +if(f1==NULL) + {printf("can't access file\n"); + exit(0); + } +fgets(pt,1000,f1); +fclose(f1); +int i; +for(i=0;pt[i]!='\0';i++) + {if(pt[i]>=97&&pt[i]<=122) + { pt[i]-=97; + ct[i]=(pt[i]+23)%26 +97; + } + else + ct[i]=pt[i]; + } +FILE *f2; +f2=fopen("nakul-caesar_decrypted.txt","w"); +if(f2==NULL) + {printf("can't access file\n"); + exit(0); + } +fputs(ct,f2); +fclose(f2); +} + diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_decrypted.txt b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_decrypted.txt new file mode 100644 index 0000000..47425db --- /dev/null +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_decrypted.txt @@ -0,0 +1,2 @@ +tlŒsrttpdr +úÿ \ No newline at end of file diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_decryption.c b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_decryption.c new file mode 100644 index 0000000..dd7b95d --- /dev/null +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-substitution_decryption.c @@ -0,0 +1,49 @@ +#include +#include +#include +void main(){ +char ct[1000],pt[1000],k[26]; + +FILE *f1; +f1=fopen("akash-substitution_ciphertext.txt","r"); + if(f1==NULL) + { + printf("can't access file\n"); + exit(0); + } +fgets(ct,1000,f1); +fclose(f1); + + +FILE *fk; +fk=fopen("akash-substitution_key.txt","r"); +if(fk==NULL) + {printf("can't access file\n"); + exit(0); + } +fgets(k,27,fk); +fclose(fk); + +printf("%s\n",k); +int i; +for(i=0;ct[i]!='\0';i++) + {if(ct[i]>=97&&ct[i]<=122) + { int a; + char c=ct[i]; + for(a=0;c!=k[a];a++) + pt[i]=97+a; + } + else + pt[i]=ct[i]; +} + +printf("%s\n",pt); +FILE *f2; +f2=fopen("nakul-substitution_decrypted.txt","w"); +if(f2==NULL) + {printf("can't access file\n"); + exit(0); + } +fputs(pt,f2); +fclose(f2); +} diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_decrypted.txt b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_decrypted.txt new file mode 100644 index 0000000..258ca80 --- /dev/null +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_decrypted.txt @@ -0,0 +1 @@ +as another day of fantasy plays out in westworld - a vast, remote park where guests pay top dollar to share wild-west adventures with android "hosts" - top programmer bernard lowe alerts park founder dr. robert ford, about incidents of aberrant behavior cropping up in some recently re-coded hosts. meanwhile in the town of sweetwater, a rancher's daughter named dolores encounters a gunslinger named teddy in the street - but their predictable narrative is upended by the appearance of a ruthless man in black and, later, by a supporting host's unscripted encounter with an artifact of the outside world. diff --git a/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_decryption.c b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_decryption.c new file mode 100644 index 0000000..d86d5bd --- /dev/null +++ b/RE-Cryptography/Sessions-5-&-6/Nakul/nakul-vigener_decryption.c @@ -0,0 +1,55 @@ +#include +#include +#include +void main(){ +char ct[1000],pt[1000],key[1000],k[1000]; +FILE *f1,*fp,*f2; + +f1=fopen("akash-vigener_ciphertext.txt","r"); +if(f1==NULL) + {printf("can't access file\n"); + exit(0); + } +fgets(pt,1000,f1); +fseek(f1,0,2); +long int len=ftell(f1); + + +fp=fopen("akash-vigener_keyfile.txt","r"); +if(fp==NULL) + {printf("can't access file\n"); + exit(0); + } +fgets(k,1000,fp); +int i,j; +int key_length=strlen(k); +for(i=0,j=0;i=97&&pt[j]<=122) + { pt[j]-=97; + key[j]-=97; + ct[j]=(pt[j]-key[j]+26)%26 +97; + } + else + ct[j]=pt[j]; + } + + +f2=fopen("nakul-vigener_decrypted.txt","w"); +if(f2==NULL) + {printf("can't access file\n"); + exit(0); + } +fputs(ct,f2); +fclose(fp); +fclose(f2); +fclose(f1); +}