0% found this document useful (0 votes)
21 views16 pages

Crypto Lab 2 Ijtimai

The document describes code for encrypting and decrypting text using Caesar, multiplicative, and affine ciphers. The code takes in a plaintext, encryption key(s), performs the encryption math, and outputs the ciphertext. It then decrypts the ciphertext back to the original plaintext.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views16 pages

Crypto Lab 2 Ijtimai

The document describes code for encrypting and decrypting text using Caesar, multiplicative, and affine ciphers. The code takes in a plaintext, encryption key(s), performs the encryption math, and outputs the ciphertext. It then decrypts the ciphertext back to the original plaintext.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

MULTIPLY wala

clc;
clear all
letter = ['a':'z'];
pt = ['thisissafecode'];
k = ['d']
key = find(letter == k)-1
for s=1:length(pt);
pt_no(s)=find(letter==pt(s))-1;
end
% pt_no
ct_no = mod((pt_no*key),26)
ct = letter(ct_no+1)

[c,d]=gcd(key,26)
key_inv = mod(d,26)
for q=1:length(ct)
ct_no1(q) = find(letter == ct(q))-1;
end

pt_no1 = mod((ct_no*key_inv),26)
pt = letter(pt_no1+1)

OUTPUT:

k=

key =

ct_no =
5 21 24 2 24 2 2 0 15 12 6 16 9 12

ct =

fvycyccapmgqjm

c=

d=

key_inv =

pt_no1 =

19 7 8 18 8 18 18 0 5 4 2 14 3 4
pt =

thisissafecode

>>

-_____________________________________________________________________

PLUS MINUS:

clc;
clear all
letter=['a':'z']
PT = ['thisissafecode']
key=['d']
key = find (letter == key) - 1
for q=1:length(PT)
PT_no(q) = find(letter == PT(q)) -1
end
CT_no=mod(PT_no+key,26)
CT=letter(CT_no+1)

for s=1:length(CT)
CT_no(s) = find(letter == CT(s)) + 1
end

PT1_Dec=mod(CT_no-key,26)
PT_Dec= letter(PT1_Dec-1)

OUTPUT:

letter =

abcdefghijklmnopqrstuvwxyz

PT =
thisissafecode

key =

key =

PT_no =

19

PT_no =

19 7

PT_no =

19 7 8

PT_no =
19 7 8 18

PT_no =

19 7 8 18 8

PT_no =

19 7 8 18 8 18

PT_no =

19 7 8 18 8 18 18

PT_no =

19 7 8 18 8 18 18 0

PT_no =

19 7 8 18 8 18 18 0 5
PT_no =

19 7 8 18 8 18 18 0 5 4

PT_no =

19 7 8 18 8 18 18 0 5 4 2

PT_no =

19 7 8 18 8 18 18 0 5 4 2 14

PT_no =

19 7 8 18 8 18 18 0 5 4 2 14 3

PT_no =

19 7 8 18 8 18 18 0 5 4 2 14 3 4

CT_no =

22 10 11 21 11 21 21 3 8 7 5 17 6 7
CT =

wklvlvvdihfrgh

CT_no =

24 10 11 21 11 21 21 3 8 7 5 17 6 7

CT_no =

24 12 11 21 11 21 21 3 8 7 5 17 6 7

CT_no =

24 12 13 21 11 21 21 3 8 7 5 17 6 7

CT_no =

24 12 13 23 11 21 21 3 8 7 5 17 6 7

CT_no =

24 12 13 23 13 21 21 3 8 7 5 17 6 7
CT_no =

24 12 13 23 13 23 21 3 8 7 5 17 6 7

CT_no =

24 12 13 23 13 23 23 3 8 7 5 17 6 7

CT_no =

24 12 13 23 13 23 23 5 8 7 5 17 6 7

CT_no =

24 12 13 23 13 23 23 5 10 7 5 17 6 7

CT_no =

24 12 13 23 13 23 23 5 10 9 5 17 6 7

CT_no =
24 12 13 23 13 23 23 5 10 9 7 17 6 7

CT_no =

24 12 13 23 13 23 23 5 10 9 7 19 6 7

CT_no =

24 12 13 23 13 23 23 5 10 9 7 19 8 7

CT_no =

24 12 13 23 13 23 23 5 10 9 7 19 8 9

PT1_Dec =

21 9 10 20 10 20 20 2 7 6 4 16 5 6

PT_Dec =

thisissafecode

>>
AFFINE WALA:
clc;
clear all
letter = ['a':'z'];
pt = ['thisissafecode'];
k1 = ['d'];
k2 = ['z'];
key1 = find(letter == k1)-1
key2 = find(letter == k2)-1
for s=1:length(pt);
pt_no(s)=find(letter==pt(s))-1
end
% pt_no
ct_no = mod((pt_no*key1+key2),26)
ct = letter(ct_no+1)

for q=1:length(ct)
ct_no1(q) = find(letter == ct(q))-1
end
[c,d] = gcd(key1,26)
key1_inv = mod(d,26);
pt_no1 = mod(((ct_no-key2)*key1_inv),26)
pt = letter(pt_no1+1)

OUTPUT:

key1 =

key2 =

25

pt_no =

19
pt_no =

19 7

pt_no =

19 7 8

pt_no =

19 7 8 18

pt_no =

19 7 8 18 8

pt_no =

19 7 8 18 8 18

pt_no =
19 7 8 18 8 18 18

pt_no =

19 7 8 18 8 18 18 0

pt_no =

19 7 8 18 8 18 18 0 5

pt_no =

19 7 8 18 8 18 18 0 5 4

pt_no =

19 7 8 18 8 18 18 0 5 4 2

pt_no =

19 7 8 18 8 18 18 0 5 4 2 14

pt_no =
19 7 8 18 8 18 18 0 5 4 2 14 3

pt_no =

19 7 8 18 8 18 18 0 5 4 2 14 3 4

ct_no =

4 20 23 1 23 1 1 25 14 11 5 15 8 11

ct =

euxbxbbzolfpil

ct_no1 =

ct_no1 =

4 20
ct_no1 =

4 20 23

ct_no1 =

4 20 23 1

ct_no1 =

4 20 23 1 23

ct_no1 =

4 20 23 1 23 1

ct_no1 =

4 20 23 1 23 1 1

ct_no1 =

4 20 23 1 23 1 1 25
ct_no1 =

4 20 23 1 23 1 1 25 14

ct_no1 =

4 20 23 1 23 1 1 25 14 11

ct_no1 =

4 20 23 1 23 1 1 25 14 11 5

ct_no1 =

4 20 23 1 23 1 1 25 14 11 5 15

ct_no1 =

4 20 23 1 23 1 1 25 14 11 5 15 8

ct_no1 =

4 20 23 1 23 1 1 25 14 11 5 15 8 11
c=

d=

pt_no1 =

19 7 8 18 8 18 18 0 5 4 2 14 3 4

pt =

thisissafecode

>>

You might also like