Professional Documents
Culture Documents
Play Fair Cipher
Play Fair Cipher
Play Fair Cipher
-------------------------------------------------------------------------
Algorithm :
4. Then split the plain text message into pairs of two letters(digraphs).
5. Pair cannot be made with same letter. Break the letter in single and add a bogus letter z
6. If both the letters are in the same column, take the letter below each one.
7. If both letters are in the same row, take the letter to the right of each one.
8. If neither of the preceding two rules are true, form a rectangle with the two letters and
Python CODE :
def matrix(key):
matrix = []
for e in key.upper():
if e not in matrix:
matrix.append(e)
alphabet = "ABCDEFGHIKLMNOPQRSTUVWXYZ"
for e in alphabet:
if e not in matrix:
matrix.append(e)
matrix_group = []
for e in range(5):
matrix_group.append('')
matrix_group[0] = matrix[0:5]
matrix_group[1] = matrix[5:10]
matrix_group[2] = matrix[10:15]
matrix_group[3] = matrix[15:20]
matrix_group[4] = matrix[20:25]
return matrix_group
def message_to_digraphs(message_original):
message = []
for e in message_original:
message.append(e)
message.remove(" ")
i=0
for e in range(int(len(message)/2)):
if message[i] == message[i+1]:
message.insert(i+1,'X')
i = i+2
if len(message) % 2 == 1:
message.append("X")
i=0
new = []
new.append(message[i:i+2])
i = i+2
return new
def find_position(key_matrix,letter):
x=y=0
for i in range(5):
for j in range(5):
if key_matrix[i][j] == letter:
x=i
y=j
return x,y
message = message_to_digraphs(message)
key_matrix = matrix(key)
cipher = []
for e in message:
p1,q1 = find_position(key_matrix,e[0])
p2,q2 = find_position(key_matrix,e[1])
if p1 == p2:
if q1 == 4:
q1 = -1
if q2 == 4:
q2 = -1
cipher.append(key_matrix[p1][q1+1])
cipher.append(key_matrix[p1][q2+1])
elif q1 == q2:
if p1 == 4:
p1 = -1;
if p2 == 4:
p2 = -1;
cipher.append(key_matrix[p1+1][q1])
cipher.append(key_matrix[p2+1][q2])
else:
cipher.append(key_matrix[p1][q2])
cipher.append(key_matrix[p2][q1])
return cipher
cipher = message_to_digraphs(cipher)
key_matrix = matrix(key)
plaintext = []
for e in cipher:
p1,q1 = find_position(key_matrix,e[0])
p2,q2 = find_position(key_matrix,e[1])
if p1 == p2:
if q1 == 4:
q1 = -1
if q2 == 4:
q2 = -1
plaintext.append(key_matrix[p1][q1-1])
plaintext.append(key_matrix[p1][q2-1])
elif q1 == q2:
if p1 == 4:
p1 = -1;
if p2 == 4:
p2 = -1;
plaintext.append(key_matrix[p1-1][q1])
plaintext.append(key_matrix[p2-1][q2])
else:
plaintext.append(key_matrix[p1][q2])
plaintext.append(key_matrix[p2][q1])
return plaintext
def main():
print("Playfair Cipher")
key = key.upper()
message = message.upper()
key_matrix = matrix(key)
print(' '.join(row))
print("Encrypting...")
print("Decrypting...")
main()
JAVA
import java.util.Scanner;
key = scanner.nextLine();
scanner.close();
createKeyTable();
uniqueKey.append(c);
if (first == second) {
processedText.append(first).append('X');
i--;
} else
processedText.append(first);
processedText.append(second);
}
// Process each digraph
return processedText.toString();
// Same row
if (posA[0] == posB[0]) {
// Same column
// Rectangle
else {
return "" + keyTable[posA[0]][posB[1]] + keyTable[posB[0]][posA[1]];
if (keyTable[i][j] == c) {
HILL CIPHER--------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------
Algorithm:
2. Split the plain text into group of length three. To fill this, add X at the end.
3. Convert each group of letters with length three into plain text vectors.
4. Replace each letter by the number corresponding to its position in the alphabet i.e.
6. Multiply the two matrices to obtain the cipher text of length three.
7. For decryption, convert each entry in the cipher text vector into its plain text vector by
import numpy
def create_matrix_from(key):
for i in range(3):
for j in range(3):
m[i][j] = ord(key[3*i+j]) % 65
return m
C=[0,0,0]
return C
cipher_text = []
P=[0, 0, 0]
for j in range(3):
P[j] = ord(message[i+j]) % 65
C = encrypt(P,K)
for j in range(3):
cipher_text.append(chr(C[j] + 65))
return "".join(cipher_text)
def MatrixInverse(K):
det = int(numpy.linalg.det(K))
for i in range(3):
for j in range(3):
Dji = K
return K_inv
def process_string(s):
s = s.upper()
if len(s) % 3 != 0:
s += 'X'
return s
if __name__ == "__main__":
key = "RRFVSVCCT"
K = create_matrix_from(key)
cipher_text = Hill(process_string(message), K)
K_inv = MatrixInverse(K)
JAVA
import java.util.Scanner;
import java.util.Arrays;
scanner.close();
plaintext += "X";
int[][] keyMatrix = {
{2, 2, 19}
};
int[][] inverseKeyMatrix = {
{4, 9, 15},
{24, 0, 17}
};
System.out.println("Padded Text: " + plaintext);
return encryptedText.toString();
return decryptedText.toString();
return result;
VIGENERE CIPHER------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------
Algorithm
table.
4. It consists of the alphabet written out 26 times in different rows, each alphabet shifted
5. At different points in the encryption process, the cipher uses a different alphabet from
PYTHON CODE :
key = list(key)
if len(message) == len(key):
return(key)
else:
key.append(key[i % len(key)])
return("" . join(key))
cipher_text = []
for i in range(len(message)):
x = (ord(message[i]) + ord(key[i])) % 26
x += ord('A')
cipher_text.append(chr(x))
return("" . join(cipher_text))
orig_text = []
for i in range(len(cipher_text)):
x += ord('A')
orig_text.append(chr(x))
return("" . join(orig_text))
def main():
main()
JAVA
import java.util.Scanner;
int x = str.length();
if (x == i)
i = 0;
if (key.length() == str.length())
break;
key+=(key.charAt(i));
return key;
String cipher_text="";
x += 'A';
cipher_text+=(char)(x);
return cipher_text;
String orig_text="";
int x = (cipher_text.charAt(i) -
x += 'A';
orig_text+=(char)(x);
return orig_text;
if(Character.isLowerCase(s.charAt(i)))
str.setCharAt(i, Character.toUpperCase(s.charAt(i)));
s = str.toString();
return s;
{
Scanner sc = new Scanner(System.in);
System.out.println("Ciphertext : "
+ cipher_text + "\n");
+ originalText(cipher_text, key));
CAESAR CIPHER---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------
Input:
Create a new alphabet by shifting each letter of the original alphabet by the shift value. For
example, if the shift value is 3, the new alphabet would be:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
DEFGHIJKLMNOPQRSTUVWXYZABC
Replace each letter of the message with the corresponding letter from the new alphabet. For
example, if the shift value is 3, the word “hello” would become “khoor”.
To decrypt the message, shift each letter back by the same amount. For example, if the shift
value is 3, the encrypted message “khoor” would become “hello”.
PYHTON CODE
def encrypt(text,s):
result = ""
# traverse text
for i in range(len(text)):
char = text[i]
if (char.isupper()):
else:
return result
text = "ATTACKATONCE"
s=4
java
//A Java Program to illustrate Caesar Cipher Technique
class CaesarCipher
if (Character.isUpperCase(text.charAt(i)))
char ch = (char)(((int)text.charAt(i) +
s - 65) % 26 + 65);
result.append(ch);
else
char ch = (char)(((int)text.charAt(i) +
s - 97) % 26 + 97);
result.append(ch);
return result;
// Driver code
int s = 4;
System.out.println("Text : " + text);
1. Write a pseudocode and program for a four-function calculator in GF(2 4 ). You should
compute the multiplicative inverses on the fly.--------------------------------------------
PYTHON CODE :
class GF2_4:
irreducible_poly=0b10011
def __init__(self,value):
def add(self,other):
def subtract(self,other):
return self.add(other)
def multiply(self,other):
result=0
temp=other.value
for i in range(4):
if(self.value>>i)&1:
result ^= temp
temp <<= 1
for i in reversed(range(4,8)):
if (result>>i) &1:
return GF2_4(result)
def inverse(self):
for i in range(1,16):
if self.multiply(GF2_4(i)).value == 1:
return GF2_4(i)
return GF2_4(0)
def divide(self,other):
return self.multiply(other.inverse())
a = GF2_4(0b0011)
b = GF2_4(0b0101)
print("Addition :",a.add(b).value)
print("Substraction :",a.subtract(b).value)
print("Multiplication :",a.multiply(b).value)
print("Division :",a.divide(b).value)
2. Write a pseudocode and program that implements fast exponentiation modulo 𝑛.---------
----------------------------------------------------------------------------------------------
PSEUDO CODE :
if modulus == 1
return 0
result = 1
if (exponent % 2 == 1)
return result
PYTHON CODE :
if modulus == 1:
return 0
result = 1
if exponent % 2 == 1:
return result
def main():
if __name__ == "__main__":
main()
3. Write a pseudocode and program for a P-box (DES) in which the permutation is defined
by a table.-----------------------------------------------------------------------------------------------
PSEUDO CODE :
output[i] = input[permutationTable[i] - 1]
return output
PYTHON CODE :
output_bits = [0]*len(permutation_table)
for i in range(len(permutation_table)):
output_bits[i]=input_bits[permutation_table[i]-1]
return output_bits
permutation_table=[16,7,20,21,
29,12,28,17,
1,15,23,26,
5,18,31,10,
2,8,24,14,
32,27,3,9,
19,13,30,6,
22,11,4,25]
input_bits=[1,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,0,1,1,1,0,0,0,1,1,1,1,0,1,0,1,0]
output_bits=pbox(input_bits,permutation_table)
4. Write a pseudocode and program for an S-box in which the input/output is defined by a
table---------------------------------------------------------------------------------------------------
PSEUDO CODE :
PYTHON CODE :
s_box = [
def SubByte(input_byte):
row = get_row(input_byte)
column = get_column(input_byte)
print(row)
print(column)
output_byte = (s_box[(row)][(column)])
return output_byte
def get_row(byte):
return ((byte) >> 4) & 0x0F
def get_column(byte):
input_byte = 0x3A
output_byte = SubByte(input_byte)
print("Input : ",hex(input_byte))
print("Output : ",hex(output_byte))
Q1. Consider a sender and receiver who need to exchange data confidentially using symmetric
encryption. Write a program that implements RC4 encryption and decryption-------------------
PYTHON CODE :
def ksa(key):
key_length = len(key)
S = list(range(256))
j=0
for i in range(256):
return S
i, j = 0, 0
ciphertext = []
j = (j + S[i]) % 256
ciphertext.append(chr(ord(char) ^ k))
return ''.join(ciphertext)
S = ksa(key)
return ciphertext
Q2. Consider a sender and receiver who need to exchange data confidentially using symmetric
encryption. Write a program that implements S-DES encryption and decryption.--------------------
PYTHON CODE:
def apply_table(inp, table):
"""
'9012345678'
'8765432109'
"""
res = ""
for i in table:
res += inp[i - 1]
return res
def left_shift(data):
"""
>>> left_shift("0123456789")
'1234567890'
"""
"""
'01011010'
"""
res = ""
for i in range(len(a)):
if a[i] == b[i]:
res += "0"
else:
res += "1"
return res
return bin(s[row][col])[2:]
left = message[:4]
right = message[4:]
r = apply_sbox(s1, temp[4:])
r = "0" * (2 - len(r)) + r
if __name__ == "__main__":
p4_table = [2, 4, 3, 1]
IP = [2, 6, 3, 1, 4, 8, 5, 7]
IP_inv = [4, 1, 3, 5, 7, 2, 8, 6]
expansion = [4, 1, 2, 3, 2, 3, 4, 1]
# key generation
left = temp[:5]
right = temp[5:]
left = left_shift(left)
right = left_shift(right)
left = left_shift(left)
right = left_shift(right)
left = left_shift(left)
right = left_shift(right)
# encryption
CT = apply_table(temp, IP_inv)
# decryption
PT = apply_table(temp, IP_inv)
Q3. Write a pseudocode and program for Round Key-Generation in DES .-----------------------------
----------------------------------------------------------------------------------------
PSEUDOCODE :
Function GenerateRoundKeys(key):
Apply Permuted Choice 1 (PC-1) to the key to get a 56-bit key (C0, D0)
For i = 1 to 16 do:
Concatenate and apply Permuted Choice 2 (PC-2) to generate the round key
Return round_keys
PYTHON CODE:
SHIFT_SCHEDULE = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1]
def generate_round_keys(key):
"""
"""
left_half = key[:28]
right_half = key[28:]
round_keys = []
round_keys.append(round_key)
return round_keys
# Example usage
key = "0001001100110100010101110111100110011011101111001101111111110001"
round_keys = generate_round_keys(key)
PSEUDOCODE :
Function KeyExpansion(key):
round_keys[] = key
For i = 4 to 44 do:
temp = round_keys[i - 1]
If i % 4 == 0 then:
temp = SubWord(temp)
Return round_keys
PYTHON CODE:
sbox = [0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab,
0x76,
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4,
0x72, 0xc0,
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8,
0x31, 0x15,
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb,
0x27, 0xb2, 0x75,
0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29,
0xe3, 0x2f, 0x84,
0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a,
0x4c, 0x58, 0xcf,
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c,
0x9f, 0xa8,
0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff,
0xf3, 0xd2,
0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64,
0x5d, 0x19, 0x73,
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde,
0x5e, 0x0b, 0xdb,
0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91,
0x95, 0xe4, 0x79,
0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65,
0x7a, 0xae, 0x08,
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b,
0xbd, 0x8b, 0x8a,
0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86,
0xc1, 0x1d, 0x9e,
0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce,
0x55, 0x28, 0xdf,
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0,
0x54, 0xbb, 0x16]
0x1b000000, 0x36000000]
def keyExpansion(key):
w = [()]*44
#fill out first 4 words based on the key
for i in range(4):
#fill out the rest based on previews words, rotword, subword and rcon values
temp = w[i-1]
word = w[i-4]
if i % 4 == 0:
x = RotWord(temp)
y = SubWord(x)
rcon = Rcon[int(i/4)]
word = ''.join(word)
temp = ''.join(temp)
return w
#convert to binary
bin1 = hex2binary(hex1)
bin2 = hex2binary(hex2)
#calculate
#cut prefix
hexed = hex(xord)[2:]
if len(hexed) != 8:
return hexed
def hex2binary(hex):
def RotWord(word):
def SubWord(word):
sWord = ()
for i in range(4):
#check first char, if its a letter(a-f) get corresponding decimal
if word[i][0].isdigit() == False:
row = ord(word[i][0]) - 86
else:
row = int(word[i][0])+1
if word[i][1].isdigit() == False:
col = ord(word[i][1]) - 86
else:
col = int(word[i][1])+1
piece = hex(sbox[sBoxIndex])[2:]
if len(piece) != 2:
#form tuple
#return string
return ''.join(sWord)
print("\n\nKeywords: \n")
for i in range(len(w)):
def main():
#hardcoding input key for demonstration purposes, could be read in from user/program
via cmd/gui etc.
key = ["0f", "15", "71", "c9", "47", "d9", "e8", "59", "0c", "b7", "ad", "d6", "af", "7f", "67", "98"]
#expand key
w = keyExpansion(key)
#display nicely
prettyPrint(w)
if __name__ == '__main__':
main()
PSEUDOCODE :
Function SubBytes(state):
PYTHON CODE :
S_BOX = (
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2,
0x75,
0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16,
def sub_byte(input_byte):
"""
"""
col = input_byte & 0x0F # Get the last 4 bits (column index)
output_byte = sub_byte(input_byte)
PSEUDOCODE :
Function ShiftRows(state):
PYTHON CODE:
def shift_rows(state):
"""
The rows of the state matrix are shifted cyclically to the left.
return state
def main():
# Example usage:
state = [
print("Original State:")
print(row)
shifted_state = shift_rows(state)
print("\nShifted State:")
print(row)
if __name__ == "__main__":
main()
Q7. Write a pseudocode and program for Mix columns Transformation in AES.-----------------------
--------------------------------------------------------------------------------------------
PSEUDOCODE :
Function MixColumns(state):
PYTHON CODE:
def mix_columns(state_matrix):
"""
Args:
Returns:
"""
"""
"""
p=0
for _ in range(8):
if b & 1:
p ^= a
if high_bit_set:
b >>= 1
return p
def mix_column(column):
"""
"""
result = [0] * 4
for i in range(4):
result[i] = (
multiply(0x02, column[i])
return result
for i in range(4):
state_matrix[i] = mix_column(state_matrix[i])
return state_matrix
# Example usage:
initial_state = [
updated_state = mix_columns(initial_state)
print(row)
CRT-------------------------------------------------------------------------------------------------------------------
-
import java.io.*;
int x = 1;
while (true)
int j;
if (x%num[j] != rem[j])
break;
if (j == k)
return x;
x++;
}
}
int k = num.length;
EUCLIDEAN---------------------------------------------------------------------------------------------------------
------
import java.util.Scanner;
int a = scanner.nextInt();
int b = scanner.nextInt();
if (b == 0) {
int s = prevResult[2];
RC4-------------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
System.out.print("\n==========================RC4Algorithm=======================
===\n");
initAndPermute(byteKey);
System.out.print(cipherText[i]);
initAndPermute(byteKey);
System.out.print(decryptedText[i]);
System.out.print("\n\n==========================RC4Algorithm=====================
=====\n");
sc.close();
} else {
keylength = byteKey.length;
S[i] = i;
int j = 0;
S[i] = S[j];
S[j] = temp;
int i = 0;
int j = 0;
int key;
int plainTextLen = 0;
// Key generation
i = (i + 1) % 256;
j = (j + S[i]) % 256;
S[i] = S[j];
S[j] = temp;
// Encryption
plainTextLen++;
return cipherText;
}
private static char[] decryptRC4(char[] cipherText) {
int i = 0;
int j = 0;
int key;
int cipherLen = 0;
// Key generation
i = (i + 1) % 256;
j = (j + S[i]) % 256;
S[i] = S[j];
S[j] = temp;
// Encryption
cipherLen++;
return plainText;