Professional Documents
Culture Documents
R1 = gx mod p.
2. Bob chooses another large random number y such that 0 ≤ y ≤ p − 1and calculates
R2 = gy mod p.
3. Alice sends R1 to Bob. Note that Alice does not send the value of x; she sends only R 1.
4. Bob sends R2 to Alice. Again, note that Bob does not send the value of y, he sends only
R2.
5. Alice calculates
K = (R2)x mod p.
6. Bob also calculates
K = (R1)y mod p.
RSA
1. Choose primes p and q
2. Calculate n = pq
3. Calculate 𝛷(𝑛) = (p-1)(q-1)
4. Select e such that gcd(φ(n), e) = 1, where 1 < e < φ(n)
5. Find d such that d ≡ e −1 (mod φ(n)) pr ed mod φ(n) = 1
DES
Key generation
1. Rearrange K using P10
2. Left shift by 1 position both the left and right halves
3. Rearrange the halves with P8 to produce K1
4. Left shift by 2 positions the left and right halves
5. Rearrange the halves with P8 to produce K2
Encryption
1. Apply the initial permutation, IP
2. Split the input in two equal halves
Round 1
3. Take the right half and Expand and permutate R using E/P
4. XOR input from step 3 with K1
5. Input left halve of step 4 into S-Box S0 and right halve into S-Box S1
6. Rearrange outputs from step 5 using P4.
7. XOR output from step 6 with Left half from step 2.
8. Swap the left and right half
AES
Key generation
1. The first step is to generate the sub-keys. The input key, K, is split into 2 words, w0
and w1.
2. The first sub-key, Key0, is in fact just the input key: Key0 = w0w1 = K
3. The other sub-keys are generated as follows:
4. w2 = w0 XOR 1000 0000 XOR SubNib(RotNib(w1)) (here 1000 0000 is the round
constant)
(Note: RotNib() is “rotate the nibbles”, which is equivalent to swapping the nibbles)
(Note: SubNib() is “apply S-Box substitution on nibbles using encryption S-Box”)
5. w3 = w2 XOR w1
6. w4 = w2 XOR 0011 0000 XOR SubNib(RotNib(w3)) (here 0011 0000 is the round
constant)
7. w5 = w4 XOR w3
Now the sub-keys are:
• Key0 = w0w1
• Key1 = w2w3
• Key2 = w4w5
Encryption
1. XoR Round 0 Key K0 with the plaintext
Round 1
2. Subbyte using the S-box table
3. Shift Row. Swap 2nd nibble and 4th nibble
4. Mix Columns
Apply the matrix multiplication with the constant matrix, Me,
1 4
Me = [ ]
4 1
0010 1110 𝑆 ′ 𝑆01 ′
Me = [ ] = [ 00 ]
1110 1110 𝑆10 ′ 𝑆11 ′
S’ = Me x S
Round 2
1. Nibble Substitution (S-boxes)
2. Shift Row (2nd and 4th)
3. Add Round Key K2
4. Ciphertext
RC4
Assume we use a 4 x 3-bit key, K, and plaintext P
4. Once the previous step for loop is done. Generate 3-bits at a time, k, that we XOR with each
3-bits of plaintext to produce the ciphertext. The 3-bits k is generated by:
i, j = 0;
while (true) {
i = (i + 1) mod 8;
j = (j + S[i]) mod 8;
Swap (S[i], S[j]);
t = (S[i] + S[j]) mod 8;
k = S[t];
}