diff --git a/css/styles.css b/css/styles.css
new file mode 100644
index 0000000..801ec23
--- /dev/null
+++ b/css/styles.css
@@ -0,0 +1,168 @@
+body {
+ font-family: Arial, sans-serif;
+ margin: 0;
+ padding: 0;
+ background-color: #ffffff;
+ background-image: url(../img/pexels-gdtography-950241.jpg);
+}
+/*new*/
+.display {
+ padding: 10px;
+ background-color: #c2c2c27c;
+ color: rgb(0, 0, 0);
+ border: none;
+ cursor: pointer;
+ border-radius: 5px;
+ margin-top: 15px;
+}
+
+.toggle-container {
+ position: fixed;
+ top: 0;
+ left: 0;
+ background-color: #8B0000;
+ padding: 10px;
+}
+
+.toggle-btn {
+ background: none;
+ border: none;
+ color: white;
+ font-size: 20px;
+ cursor: pointer;
+}
+
+.dropdown {
+ display: none;
+ position: absolute;
+ top: 100%;
+ left: 50%;
+ transform: translateX(-50%);
+}
+
+.dropdown-content {
+ background-color: #ffffff;
+ box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
+ z-index: 1;
+ text-align: center;
+}
+
+.dropdown-content a {
+ color: black;
+ padding: 12px 16px;
+ text-decoration: none;
+ display: block;
+}
+
+.dropdown-content a:hover {
+ background-color: #ffffff;
+}
+
+.toggle-container:hover .dropdown {
+ display: block;
+}
+
+.header {
+ background-color: #8B0000;
+ padding: 10px;
+ text-align: center;
+}
+
+.header-title {
+ color: white;
+ margin: 0;
+}
+
+.container {
+ display: flex;
+ justify-content: space-between;
+ margin: 20px;
+}
+
+.left-panel,
+.right-panel {
+ width: 45%;
+ padding: 20px;
+ background-color: white;
+ border-radius: 5px;
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
+}
+
+.separator {
+ width: 10px;
+ background-color: #ffffff;
+}
+
+.input-group {
+ margin-bottom: 15px;
+}
+
+label {
+ display: block;
+ margin-bottom: 5px;
+ font-weight: bold;
+}
+
+input {
+ width: 100%;
+ padding: 10px;
+ margin-bottom: 10px;
+ box-sizing: border-box;
+}
+
+.action-button {
+ padding: 10px;
+ background-color: #5c93f3;
+ color: white;
+ border: none;
+ cursor: pointer;
+ border-radius: 5px;
+}
+
+@media (max-width: 768px) {
+ .container {
+ flex-direction: column;
+ }
+
+ .left-panel,
+ .right-panel {
+ width: 100%;
+ margin-bottom: 20px;
+ }
+
+ .separator {
+ display: none;
+ }
+}
+.links{
+ color: black;
+ font-family: Verdana, Geneva, Tahoma, sans-serif;
+ text-decoration: none;
+ font-size: 15px;
+}
+.links:hover{
+ color: #8B0000;
+}
+h2,h3,h4{
+ color: #850606;
+ font-family: Verdana, Geneva, Tahoma, sans-serif;
+ font-weight: 100px;
+}
+.modes{
+ background-color: rgb(228, 224, 219);
+ text-align: center;
+ padding-top: 15px;
+ padding-bottom: 20px;
+}
+#about{
+ background-color: rgb(255, 255, 255);
+ color: rgb(0, 0, 0);
+ margin: 50px;
+ text-align:left;
+ padding: 50px;
+ margin-right: 50px;
+ padding-left: 50px;
+ font-size: 15px;
+}
+
+
\ No newline at end of file
diff --git a/html/CBCmode.html b/html/CBCmode.html
new file mode 100644
index 0000000..4a21859
--- /dev/null
+++ b/html/CBCmode.html
@@ -0,0 +1,88 @@
+
+
+
+
+
+
+
+ Hight Cipher
+
+
+
+
+
+
+
+
+
+
Encryption
+
+ Plain Text (64-bit hexadecimal):
+
+
+
+ Key (128-bit hexadecimal):
+
+
+
Encrypt
+
+
+
+
+
+
+
Decryption
+
+ Cipher Text (64-bit hexadecimal):
+
+
+
+ Key (128-bit hexadecimal):
+
+
+
Decrypt
+
+
+
+
+
+
+ Hight CBC Cipher Information
+ - The user input for the key should be 128 bits and in hexadecimal format.
+ - The user input for plaintext or ciphertext can be of any length, both greater than or less than 64 bits, and in hexadecimal format.
+ - Padding scheme used for this block cipher is “OneAndZeroes Padding”.
+
+
+
+ Hexadecimal Value Input
+ Hexadecimal values can be input with or without spaces between the characters.
+
+
+
+ Example:
+ Key: 00112233445566778899aabbccddeeff
+ Plaintext: 00000000000000002e
+ Ciphertext: 00f418aed94f03f2ca5b4e9b9258aac3
+
+
+
+
+
+
+
+
+
diff --git a/html/ECBmode.html b/html/ECBmode.html
new file mode 100644
index 0000000..cce08d4
--- /dev/null
+++ b/html/ECBmode.html
@@ -0,0 +1,97 @@
+
+
+
+
+
+
+
+ Hight Cipher
+
+
+
+
+
+
+
+
+
+
Encryption
+
+ Plain Text (64-bit hexadecimal):
+
+
+
+ Key (128-bit hexadecimal):
+
+
+
Encrypt
+
+
+
+
+
+
+
Decryption
+
+ Cipher Text (64-bit hexadecimal):
+
+
+
+ Key (128-bit hexadecimal):
+
+
+
Decrypt
+
+
+
+
+
+
+
+ Hight ECB Cipher Information
+ - The user input for the key should be 128 bit and in hexadecimal format.
+ - The user input for plaintext or ciphertext can be of any length, both greater than or less than 64 bits, and in hexadecimal format.
+ - A padding block has been added to ever plaintext encryption.
+ - Padding scheme used for this block cipher is “OneAndZeroes Padding”.
+
+
+
+ Hexadecimal Value Input
+ Hexadecimal values can be input with or without spaces between the characters.
+
+
+
+ Example:
+ Key: 00112233445566778899aabbccddeeff
+ Plaintext: 0000000000000000
+ Ciphertext: 00f418aed94f03f2
+
+
+
+ Hight ECB Example:
+ Key: 00112233445566778899aabbccddeeff
+ Plaintext: 00000000000000002e
+ Ciphertext: 00f418aed94f03f2a17ff6f60354dbc2
+
+
+
+
+
+
+
+
+
diff --git a/html/about.html b/html/about.html
new file mode 100644
index 0000000..ec1e2c6
--- /dev/null
+++ b/html/about.html
@@ -0,0 +1,75 @@
+
+
+
+
+
+
+
+ Hight Cipher
+
+
+
+
+
+
+
+
+ About HIGHT
+ HIGHT is an acronym for HIGh security and light weigHT encryption algorithm. It's designed for low-resource devices and offers strong security with its 64-bit block size and 128-bit keys.
+ The algorithm's core components include round functions, key schedule, encryption, and decryption processes.
+
+ Round Functions
+ HIGHT utilizes two round functions: F0 and F1. Both involve circular shifts and XOR operations on 8-bit values.
+
+ F0(x) = (x<<<1) [^] (x<<<2) [^] (x<<<7)
+ F1(x) = (x<<<3) [^] (x<<<4) [^] (x<<<6)
+
+
+ Key Schedule
+ HIGHT generates 128 subkeys and a whitening key, all derived from the 128-bit master key using a dedicated key scheduling algorithm.
+
+ Encryption
+ Whitening enhances the cipher's diffusion and confusion properties, increasing its resistance to attacks. The plaintext undergoes 32 rounds, utilizing four subkeys and round functions in each.
+
+ Decryption
+ Decryption reverses the encryption process to recover the original plaintext. All key generation and round functions remain the same.
+
+
Modes of Operation
+
HIGHT supports two modes of operation:
+
+
Electronic Codebook (ECB)
+
The plaintext is divided into 64-bit blocks, each encrypted independently with the same key. The resulting ciphertext blocks are then concatenated.
+
OneAndZeroes Padding is used to ensure block size consistency.
+
+
Cipher Block Chaining (CBC)
+
Similar to ECB, plaintext is divided into 64-bit blocks. However, each block is XORed with the previous ciphertext block before encryption, creating a chain of dependencies.
+
An Initialization Vector (IV) is used to start the chain. This website uses 00 00 00 00 00 00 00 00 as the default IV.
+
OneAndZeroes Padding is also used with CBC.
+
+
+
+
+
+
+
diff --git a/html/plain_CBCmode.html b/html/plain_CBCmode.html
new file mode 100644
index 0000000..568562f
--- /dev/null
+++ b/html/plain_CBCmode.html
@@ -0,0 +1,94 @@
+
+
+
+
+
+
+
+ Hight Cipher
+
+
+
+
+
+
+
+
+
+
Encryption
+
+ Plain Text:
+
+
+
+ Key (128-bit hexadecimal):
+
+
+
Encrypt
+
+
+
+
+
+
+
Decryption
+
+ Cipher Text:
+
+
+
+ Key (128-bit hexadecimal):
+
+
+
Decrypt
+
+
+
+
+
+
+ Hight CBC Cipher Information
+ - The user input for the key should be 128 bits and in hexadecimal format.
+ - The user input for plaintext can be of any length, both greater than or less than 64 bits, and in ASCII format.
+ - Padding scheme used for this block cipher is “OneAndZeroes Padding”.
+
+
+
+ Hexadecimal Value Input
+ Hexadecimal values can be input with or without spaces between the characters.
+
+
+
+ Example:
+ Key: 00112233445566778899aabbccddeeff
+ Plaintext: this is amal
+ Ciphertext: 00 29 69 3d 4f 5d 91 c9 89 73 eb cb d2 f5 d9 19
+
+
+
+ Note:
+ you may find this character '' at the end of Decryption Result,
+ ignore it, its the padding block.
+
+
+
+
+
+
+
+
+
diff --git a/html/plain_ECBmode.html b/html/plain_ECBmode.html
new file mode 100644
index 0000000..cf08e4f
--- /dev/null
+++ b/html/plain_ECBmode.html
@@ -0,0 +1,96 @@
+
+
+
+
+
+
+
+ Hight Cipher
+
+
+
+
+
+
+
+
+
+
Encryption
+
+ Plain Text:
+
+
+
+ Key (128-bit hexadecimal):
+
+
+
Encrypt
+
+
+
+
+
+
+
Decryption
+
+ Cipher Text:
+
+
+
+ Key (128-bit hexadecimal):
+
+
+
Decrypt
+
+
+
+
+
+
+
+ Hight ECB Cipher Information
+ - The user input for the key should be 128 bit and in hexadecimal format.
+ - The user input for plaintext can be of any length, both greater than or less than 64 bits, and in ASCII format.
+ - A padding block has been added to ever plaintext encryption.
+ - Padding scheme used for this block cipher is “OneAndZeroes Padding”.
+
+
+
+ Hexadecimal Value Input
+ Hexadecimal values can be input with or without spaces between the characters.
+
+
+
+ Plaintext ECB Example:
+ Key: 00112233445566778899aabbccddeeff
+ Plaintext: this is amal
+ Ciphertext: 00 29 69 3d 4f 5d 91 c9 0b f9 aa 86 6e a9 ce 90
+
+
+
+ Note:
+ you may find this character '' at the end of Decryption Result,
+ ignore it, its the padding block.
+
+
+
+
+
+
+
+
+
diff --git a/img/pexels-gdtography-950241.jpg b/img/pexels-gdtography-950241.jpg
new file mode 100644
index 0000000..28ff3a8
Binary files /dev/null and b/img/pexels-gdtography-950241.jpg differ
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..9afacad
--- /dev/null
+++ b/index.html
@@ -0,0 +1,87 @@
+
+
+
+
+
+
+
+ Hight Cipher
+
+
+
+
+
+
+
+
+
+
Encryption
+
+ Plain Text (64-bit hexadecimal):
+
+
+
+ Key (128-bit hexadecimal):
+
+
+
Encrypt
+
+
+
+
+
+
+
Decryption
+
+ Cipher Text (64-bit hexadecimal):
+
+
+
+ Key (128-bit hexadecimal):
+
+
+
Decrypt
+
+
+
+
+
+
+ Hight Classic Cipher Information
+ - The user input for the key should be 128 bits and in hexadecimal format.
+ - The user input for plaintext or ciphertext should be 64 bits and in hexadecimal format.
+ - The value of plaintext or ciphertext should not exceed 64 bits. If you need to encrypt data larger than 64 bits, consider using ECB or CBC modes.
+
+
+
+ Hexadecimal Value Input
+ Hexadecimal values can be input with or without spaces between the characters.
+
+
+
+ Example:
+ Key: 00112233445566778899aabbccddeeff
+ Plaintext: 0000000000000000
+ Ciphertext: 00f418aed94f03f2
+
+
+
+
+
+
+
+
diff --git a/js/cbc.js b/js/cbc.js
new file mode 100644
index 0000000..8308f0a
--- /dev/null
+++ b/js/cbc.js
@@ -0,0 +1,325 @@
+let mk = []; // list of master key
+let wk = []; // list of whitening key
+let s = [0, 1, 0, 1, 1, 0, 1];
+let d = [];
+let sk = new Array(128).fill(0);
+let x = new Array(8).fill(0);
+
+let key = "";
+let pt = [];
+let plainText = "";
+let ct = [];
+let cipherText = "";
+
+function f0(val) {
+ val=val.toString(2).padStart(8, '0');
+ let ans = parseInt(val[1]+val[2]+val[3]+val[4]+val[5]+val[6]+val[7]+val[0],2) ^ parseInt(val[2]+val[3]+val[4]+val[5]+val[6]+val[7]+val[0]+val[1],2) ^ parseInt(val[7]+val[0]+val[1]+val[2]+val[3]+val[4]+val[5]+val[6],2)
+ return ans;
+}
+
+function f1(val) {
+ val=val.toString(2).padStart(8, '0');
+ let ans = parseInt(val[3]+val[4]+val[5]+val[6]+val[7]+val[0]+val[1]+val[2],2) ^ parseInt(val[4]+val[5]+val[6]+val[7]+val[0]+val[1]+val[2]+val[3],2) ^ parseInt(val[6]+val[7]+val[0]+val[1]+val[2]+val[3]+val[4]+val[5],2)
+ return ans;
+}
+
+function generateMkWk() {
+ for (let i = 0; i < key.length; i=i+2) {
+ mk.push(key.slice(i, i + 2));
+ }
+
+ mk = mk.map(item => {
+ return parseInt(item, 16);
+ });
+
+ let tmp = [];
+ for (let i = 0; i < key.length; i += 2) {
+ tmp.push(key.slice(i, i + 2));
+ }
+
+ for (let i = 12; i < 16; i++) {
+ wk.push(parseInt(tmp[i], 16));
+ }
+
+ for (let i = 0; i < 4; i++) {
+ wk.push(parseInt(tmp[i], 16));
+ }
+}
+
+function generateSD() {
+ let tmpD = [s[6], s[5], s[4], s[3], s[2], s[1], s[0]];
+ let tmp2D = tmpD.join('');
+ d.push(tmp2D);
+
+ for (let i = 1; i < 128; i++) {
+ let tmpS = s[i + 2] ^ s[i - 1];
+ tmpD = [tmpS, s[i + 5], s[i + 4], s[i + 3], s[i + 2], s[i + 1], s[i]];
+ tmp2D = tmpD.join('');
+ s.push(tmpS);
+ d.push(tmp2D);
+ }
+ for (let i=0;i {
+ return parseInt(item, 16).toString(2).padStart(8, '0');
+ });
+
+ for (let i=0;i= 0; i--) {
+ tmp_x = [...x];
+ x[0] = tmp_x[1];
+ x[2] = tmp_x[3];
+ x[4] = tmp_x[5];
+ x[6] = tmp_x[7];
+ x[1] = ((tmp_x[2]) - (f1(x[0]) ^ sk[4 * i + 2]) + 256) % 256;
+ x[3] = (tmp_x[4]) ^ (((f0(x[2])) + (sk[4 * i + 1])) % 256);
+ x[5] = ((tmp_x[6]) - (f1(x[4]) ^ sk[4 * i]) + 256) % 256;
+ x[7] = (tmp_x[0]) ^ (((f0(x[6])) + (sk[4 * i + 3])) % 256);
+ }
+}
+
+function final_dec() {
+ let X0 = [...x];
+ let WK = wk.slice().reverse();
+ x[0] = ((X0[0] - WK[0]) + 256) % 256;
+ x[2] = (X0[2] ^ WK[1]);
+ x[4] = ((X0[4] - WK[2]) + 256) % 256;
+ x[6] = (X0[6] ^ WK[3]);
+ x[1] = X0[1];
+ x[3] = X0[3];
+ x[5] = X0[5];
+ x[7] = X0[7];
+}
+
+function main_dec() {
+ generateMkWk();
+ generateSD();
+ generateSK();
+ initial_dec();
+ decryption();
+ final_dec();
+ tmp_pt_ans = "";
+ for (let i = 1; i <= 8; i++) {
+ tmp_pt_ans += (x[x.length - i]).toString(16).padStart(2, '0');
+ }
+ return tmp_pt_ans;
+}
+
+function start_dec(){
+ //key="ffeeddccbbaa99887766554433221100";
+ key = document.getElementById('decryptKey').value;
+ key = key.replace(/\s/g, '');
+
+ //tmp_plainText = "00112233445566771111223344556677";
+ let tmp_cipherText = document.getElementById('cipherText').value;
+ tmp_cipherText = tmp_cipherText.replace(/\s/g, '');
+
+ z=0;y=16;
+ let intitial_cp="0000000000000000"
+ let plaintext = "Plaintext:";
+ for(let i=1;i<(Math.floor(tmp_cipherText.length/16))+1;i++){
+ cipherText=tmp_cipherText.substring(z,y);
+ pt_ans=main_dec();
+ final_ans = cbc_xor(intitial_cp,pt_ans)
+ intitial_cp=tmp_cipherText.substring(z,y);
+ z=z+16;
+ y=y+16;
+ plaintext = plaintext +" "+ final_ans;
+
+ //restoring global variables
+ mk = [];wk = [];
+ s = [0, 1, 0, 1, 1, 0, 1];
+ d = [];ct = [];
+ sk = new Array(128).fill(0);
+ x = new Array(8).fill(0);
+ cipherText = "";
+ }
+ key = "";
+ console.log(plaintext);
+ document.getElementById('decryptionResult').innerHTML = plaintext;
+}
\ No newline at end of file
diff --git a/js/classic.js b/js/classic.js
new file mode 100644
index 0000000..a54625d
--- /dev/null
+++ b/js/classic.js
@@ -0,0 +1,280 @@
+let mk = []; // list of master key
+let wk = []; // list of whitening key
+let s = [0, 1, 0, 1, 1, 0, 1];
+let d = [];
+let sk = new Array(128).fill(0);
+let x = new Array(8).fill(0);
+
+let key = "";
+let pt = [];
+let plainText = "";
+let ct = [];
+let cipherText = "";
+
+function f0(val) {
+ val=val.toString(2).padStart(8, '0');
+ let ans = parseInt(val[1]+val[2]+val[3]+val[4]+val[5]+val[6]+val[7]+val[0],2) ^ parseInt(val[2]+val[3]+val[4]+val[5]+val[6]+val[7]+val[0]+val[1],2) ^ parseInt(val[7]+val[0]+val[1]+val[2]+val[3]+val[4]+val[5]+val[6],2)
+ return ans;
+}
+
+function f1(val) {
+ val=val.toString(2).padStart(8, '0');
+ let ans = parseInt(val[3]+val[4]+val[5]+val[6]+val[7]+val[0]+val[1]+val[2],2) ^ parseInt(val[4]+val[5]+val[6]+val[7]+val[0]+val[1]+val[2]+val[3],2) ^ parseInt(val[6]+val[7]+val[0]+val[1]+val[2]+val[3]+val[4]+val[5],2)
+ return ans;
+}
+
+function generateMkWk() {
+ for (let i = 0; i < key.length; i=i+2) {
+ mk.push(key.slice(i, i + 2));
+ }
+
+ mk = mk.map(item => {
+ return parseInt(item, 16);
+ });
+
+ let tmp = [];
+ for (let i = 0; i < key.length; i += 2) {
+ tmp.push(key.slice(i, i + 2));
+ }
+
+ for (let i = 12; i < 16; i++) {
+ wk.push(parseInt(tmp[i], 16));
+ }
+
+ for (let i = 0; i < 4; i++) {
+ wk.push(parseInt(tmp[i], 16));
+ }
+}
+
+function generateSD() {
+ let tmpD = [s[6], s[5], s[4], s[3], s[2], s[1], s[0]];
+ let tmp2D = tmpD.join('');
+ d.push(tmp2D);
+
+ for (let i = 1; i < 128; i++) {
+ let tmpS = s[i + 2] ^ s[i - 1];
+ tmpD = [tmpS, s[i + 5], s[i + 4], s[i + 3], s[i + 2], s[i + 1], s[i]];
+ tmp2D = tmpD.join('');
+ s.push(tmpS);
+ d.push(tmp2D);
+ }
+ for (let i=0;i {
+ return parseInt(item, 16).toString(2).padStart(8, '0');
+ });
+
+ for (let i=0;i= 0; i--) {
+ tmp_x = [...x];
+ x[0] = tmp_x[1];
+ x[2] = tmp_x[3];
+ x[4] = tmp_x[5];
+ x[6] = tmp_x[7];
+ x[1] = ((tmp_x[2]) - (f1(x[0]) ^ sk[4 * i + 2]) + 256) % 256;
+ x[3] = (tmp_x[4]) ^ (((f0(x[2])) + (sk[4 * i + 1])) % 256);
+ x[5] = ((tmp_x[6]) - (f1(x[4]) ^ sk[4 * i]) + 256) % 256;
+ x[7] = (tmp_x[0]) ^ (((f0(x[6])) + (sk[4 * i + 3])) % 256);
+ }
+}
+
+function final_dec() {
+ let X0 = [...x];
+ let WK = wk.slice().reverse();
+ x[0] = ((X0[0] - WK[0]) + 256) % 256;
+ x[2] = (X0[2] ^ WK[1]);
+ x[4] = ((X0[4] - WK[2]) + 256) % 256;
+ x[6] = (X0[6] ^ WK[3]);
+ x[1] = X0[1];
+ x[3] = X0[3];
+ x[5] = X0[5];
+ x[7] = X0[7];
+}
+
+function main_dec() {
+ generateMkWk();
+ generateSD();
+ generateSK();
+ initial_dec();
+ decryption();
+ final_dec();
+ let plaintext = "Plaintext:";
+ for (let i = 1; i <= 8; i++) {
+ plaintext = plaintext +" "+ (x[x.length - i]).toString(16).padStart(2, '0');
+ }
+ console.log(plaintext);
+ document.getElementById('decryptionResult').innerHTML = plaintext;
+}
+
+function start_dec(){
+ //key = "ffeeddccbbaa99887766554433221100";
+ key = document.getElementById('decryptKey').value;
+ key = key.replace(/\s/g, '');
+ //cipherText = "23ce9f72e543e6d8";
+ cipherText = document.getElementById('cipherText').value;
+ cipherText = cipherText.replace(/\s/g, '');
+ main_dec();
+
+ //restoring global variables
+ mk = [];wk = [];
+ s = [0, 1, 0, 1, 1, 0, 1];
+ d = [];ct = [];
+ sk = new Array(128).fill(0);
+ x = new Array(8).fill(0);
+ cipherText = "";key = "";
+}
\ No newline at end of file
diff --git a/js/ecb.js b/js/ecb.js
new file mode 100644
index 0000000..b838441
--- /dev/null
+++ b/js/ecb.js
@@ -0,0 +1,316 @@
+let mk = []; // list of master key
+let wk = []; // list of whitening key
+let s = [0, 1, 0, 1, 1, 0, 1];
+let d = [];
+let sk = new Array(128).fill(0);
+let x = new Array(8).fill(0);
+
+let key = "";
+let pt = [];
+let plainText = "";
+let ct = [];
+let cipherText = "";
+
+function f0(val) {
+ val=val.toString(2).padStart(8, '0');
+ let ans = parseInt(val[1]+val[2]+val[3]+val[4]+val[5]+val[6]+val[7]+val[0],2) ^ parseInt(val[2]+val[3]+val[4]+val[5]+val[6]+val[7]+val[0]+val[1],2) ^ parseInt(val[7]+val[0]+val[1]+val[2]+val[3]+val[4]+val[5]+val[6],2)
+ return ans;
+}
+
+function f1(val) {
+ val=val.toString(2).padStart(8, '0');
+ let ans = parseInt(val[3]+val[4]+val[5]+val[6]+val[7]+val[0]+val[1]+val[2],2) ^ parseInt(val[4]+val[5]+val[6]+val[7]+val[0]+val[1]+val[2]+val[3],2) ^ parseInt(val[6]+val[7]+val[0]+val[1]+val[2]+val[3]+val[4]+val[5],2)
+ return ans;
+}
+
+function generateMkWk() {
+ for (let i = 0; i < key.length; i=i+2) {
+ mk.push(key.slice(i, i + 2));
+ }
+
+ mk = mk.map(item => {
+ return parseInt(item, 16);
+ });
+
+ let tmp = [];
+ for (let i = 0; i < key.length; i += 2) {
+ tmp.push(key.slice(i, i + 2));
+ }
+
+ for (let i = 12; i < 16; i++) {
+ wk.push(parseInt(tmp[i], 16));
+ }
+
+ for (let i = 0; i < 4; i++) {
+ wk.push(parseInt(tmp[i], 16));
+ }
+}
+
+function generateSD() {
+ let tmpD = [s[6], s[5], s[4], s[3], s[2], s[1], s[0]];
+ let tmp2D = tmpD.join('');
+ d.push(tmp2D);
+
+ for (let i = 1; i < 128; i++) {
+ let tmpS = s[i + 2] ^ s[i - 1];
+ tmpD = [tmpS, s[i + 5], s[i + 4], s[i + 3], s[i + 2], s[i + 1], s[i]];
+ tmp2D = tmpD.join('');
+ s.push(tmpS);
+ d.push(tmp2D);
+ }
+ for (let i=0;i {
+ return parseInt(item, 16).toString(2).padStart(8, '0');
+ });
+
+ for (let i=0;i= 0; i--) {
+ tmp_x = [...x];
+ x[0] = tmp_x[1];
+ x[2] = tmp_x[3];
+ x[4] = tmp_x[5];
+ x[6] = tmp_x[7];
+ x[1] = ((tmp_x[2]) - (f1(x[0]) ^ sk[4 * i + 2]) + 256) % 256;
+ x[3] = (tmp_x[4]) ^ (((f0(x[2])) + (sk[4 * i + 1])) % 256);
+ x[5] = ((tmp_x[6]) - (f1(x[4]) ^ sk[4 * i]) + 256) % 256;
+ x[7] = (tmp_x[0]) ^ (((f0(x[6])) + (sk[4 * i + 3])) % 256);
+ }
+}
+
+function final_dec() {
+ let X0 = [...x];
+ let WK = wk.slice().reverse();
+ x[0] = ((X0[0] - WK[0]) + 256) % 256;
+ x[2] = (X0[2] ^ WK[1]);
+ x[4] = ((X0[4] - WK[2]) + 256) % 256;
+ x[6] = (X0[6] ^ WK[3]);
+ x[1] = X0[1];
+ x[3] = X0[3];
+ x[5] = X0[5];
+ x[7] = X0[7];
+}
+
+function main_dec() {
+ generateMkWk();
+ generateSD();
+ generateSK();
+ initial_dec();
+ decryption();
+ final_dec();
+ /*let plaintext = "Plaintext: ";
+ for (let i = 1; i <= 8; i++) {
+ plaintext += (x[x.length - i]).toString(16).padStart(2, '0');
+ }
+ //console.log(plaintext);
+ document.getElementById('decryptionResult').innerHTML = plaintext;*/
+}
+
+function start_dec(){
+ //key="ffeeddccbbaa99887766554433221100";
+ key = document.getElementById('decryptKey').value;
+ key = key.replace(/\s/g, '');
+
+ //let tmp_plainText = "00112233445566771111223344556677";
+ let tmp_cipherText = document.getElementById('cipherText').value;
+ tmp_cipherText = tmp_cipherText.replace(/\s/g, '');
+ //plainText="0011223344556677"
+
+ z=0;y=16;
+ let plaintext = "Plaintext:";
+ for(let i=1;i<(Math.floor(tmp_cipherText.length/16))+1;i++){
+ cipherText=tmp_cipherText.substring(z,y);
+ main_dec();
+ z=z+16;
+ y=y+16;
+ for (let i = 1; i <= 8; i++) {
+ plaintext = plaintext +" "+ (x[x.length - i]).toString(16).padStart(2, '0');
+ }
+
+ //restoring global variables
+ mk = [];wk = [];
+ s = [0, 1, 0, 1, 1, 0, 1];
+ d = [];ct = [];
+ sk = new Array(128).fill(0);
+ x = new Array(8).fill(0);
+ cipherText = "";
+ }
+ key = "";
+ console.log(plaintext);
+ document.getElementById('decryptionResult').innerHTML = plaintext;
+}
\ No newline at end of file
diff --git a/js/plain_cbc.js b/js/plain_cbc.js
new file mode 100644
index 0000000..3d6bd59
--- /dev/null
+++ b/js/plain_cbc.js
@@ -0,0 +1,346 @@
+let mk = []; // list of master key
+let wk = []; // list of whitening key
+let s = [0, 1, 0, 1, 1, 0, 1];
+let d = [];
+let sk = new Array(128).fill(0);
+let x = new Array(8).fill(0);
+
+let key = "";
+let pt = [];
+let plainText = "";
+let ct = [];
+let cipherText = "";
+
+function f0(val) {
+ val=val.toString(2).padStart(8, '0');
+ let ans = parseInt(val[1]+val[2]+val[3]+val[4]+val[5]+val[6]+val[7]+val[0],2) ^ parseInt(val[2]+val[3]+val[4]+val[5]+val[6]+val[7]+val[0]+val[1],2) ^ parseInt(val[7]+val[0]+val[1]+val[2]+val[3]+val[4]+val[5]+val[6],2)
+ return ans;
+}
+
+function f1(val) {
+ val=val.toString(2).padStart(8, '0');
+ let ans = parseInt(val[3]+val[4]+val[5]+val[6]+val[7]+val[0]+val[1]+val[2],2) ^ parseInt(val[4]+val[5]+val[6]+val[7]+val[0]+val[1]+val[2]+val[3],2) ^ parseInt(val[6]+val[7]+val[0]+val[1]+val[2]+val[3]+val[4]+val[5],2)
+ return ans;
+}
+
+function generateMkWk() {
+ for (let i = 0; i < key.length; i=i+2) {
+ mk.push(key.slice(i, i + 2));
+ }
+
+ mk = mk.map(item => {
+ return parseInt(item, 16);
+ });
+
+ let tmp = [];
+ for (let i = 0; i < key.length; i += 2) {
+ tmp.push(key.slice(i, i + 2));
+ }
+
+ for (let i = 12; i < 16; i++) {
+ wk.push(parseInt(tmp[i], 16));
+ }
+
+ for (let i = 0; i < 4; i++) {
+ wk.push(parseInt(tmp[i], 16));
+ }
+}
+
+function generateSD() {
+ let tmpD = [s[6], s[5], s[4], s[3], s[2], s[1], s[0]];
+ let tmp2D = tmpD.join('');
+ d.push(tmp2D);
+
+ for (let i = 1; i < 128; i++) {
+ let tmpS = s[i + 2] ^ s[i - 1];
+ tmpD = [tmpS, s[i + 5], s[i + 4], s[i + 3], s[i + 2], s[i + 1], s[i]];
+ tmp2D = tmpD.join('');
+ s.push(tmpS);
+ d.push(tmp2D);
+ }
+ for (let i=0;i {
+ return parseInt(item, 16).toString(2).padStart(8, '0');
+ });
+
+ for (let i=0;i= 0; i--) {
+ tmp_x = [...x];
+ x[0] = tmp_x[1];
+ x[2] = tmp_x[3];
+ x[4] = tmp_x[5];
+ x[6] = tmp_x[7];
+ x[1] = ((tmp_x[2]) - (f1(x[0]) ^ sk[4 * i + 2]) + 256) % 256;
+ x[3] = (tmp_x[4]) ^ (((f0(x[2])) + (sk[4 * i + 1])) % 256);
+ x[5] = ((tmp_x[6]) - (f1(x[4]) ^ sk[4 * i]) + 256) % 256;
+ x[7] = (tmp_x[0]) ^ (((f0(x[6])) + (sk[4 * i + 3])) % 256);
+ }
+}
+
+function final_dec() {
+ let X0 = [...x];
+ let WK = wk.slice().reverse();
+ x[0] = ((X0[0] - WK[0]) + 256) % 256;
+ x[2] = (X0[2] ^ WK[1]);
+ x[4] = ((X0[4] - WK[2]) + 256) % 256;
+ x[6] = (X0[6] ^ WK[3]);
+ x[1] = X0[1];
+ x[3] = X0[3];
+ x[5] = X0[5];
+ x[7] = X0[7];
+}
+
+function main_dec() {
+ generateMkWk();
+ generateSD();
+ generateSK();
+ initial_dec();
+ decryption();
+ final_dec();
+ tmp_pt_ans = "";
+ for (let i = 1; i <= 8; i++) {
+ tmp_pt_ans += (x[x.length - i]).toString(16).padStart(2, '0');
+ }
+ return tmp_pt_ans;
+}
+
+function start_dec(){
+ //key="ffeeddccbbaa99887766554433221100";
+ key = document.getElementById('decryptKey').value;
+ key = key.replace(/\s/g, '');
+
+ //tmp_plainText = "00112233445566771111223344556677";
+ let tmp_cipherText = document.getElementById('cipherText').value;
+ tmp_cipherText = tmp_cipherText.replace(/\s/g, '');
+
+ z=0;y=16;
+ let intitial_cp="0000000000000000"
+ let plaintext = "";
+ for(let i=1;i<(Math.floor(tmp_cipherText.length/16))+1;i++){
+ cipherText=tmp_cipherText.substring(z,y);
+ pt_ans=main_dec();
+ final_ans = cbc_xor(intitial_cp,pt_ans)
+ intitial_cp=tmp_cipherText.substring(z,y);
+ z=z+16;
+ y=y+16;
+ plaintext = plaintext +" "+ final_ans;
+
+ //restoring global variables
+ mk = [];wk = [];
+ s = [0, 1, 0, 1, 1, 0, 1];
+ d = [];ct = [];
+ sk = new Array(128).fill(0);
+ x = new Array(8).fill(0);
+ cipherText = "";
+ }
+ key = "";
+ plaintext = plaintext.replace(/\s/g, '');
+ console.log(plaintext);
+ plaintext = hexToAscii(plaintext);
+ document.getElementById('decryptionResult').innerHTML = 'Plaintext: ' + plaintext;
+}
\ No newline at end of file
diff --git a/js/plain_ecb.js b/js/plain_ecb.js
new file mode 100644
index 0000000..4eb973b
--- /dev/null
+++ b/js/plain_ecb.js
@@ -0,0 +1,338 @@
+let mk = []; // list of master key
+let wk = []; // list of whitening key
+let s = [0, 1, 0, 1, 1, 0, 1];
+let d = [];
+let sk = new Array(128).fill(0);
+let x = new Array(8).fill(0);
+
+let key = "";
+let pt = [];
+let plainText = "";
+let ct = [];
+let cipherText = "";
+
+function f0(val) {
+ val=val.toString(2).padStart(8, '0');
+ let ans = parseInt(val[1]+val[2]+val[3]+val[4]+val[5]+val[6]+val[7]+val[0],2) ^ parseInt(val[2]+val[3]+val[4]+val[5]+val[6]+val[7]+val[0]+val[1],2) ^ parseInt(val[7]+val[0]+val[1]+val[2]+val[3]+val[4]+val[5]+val[6],2)
+ return ans;
+}
+
+function f1(val) {
+ val=val.toString(2).padStart(8, '0');
+ let ans = parseInt(val[3]+val[4]+val[5]+val[6]+val[7]+val[0]+val[1]+val[2],2) ^ parseInt(val[4]+val[5]+val[6]+val[7]+val[0]+val[1]+val[2]+val[3],2) ^ parseInt(val[6]+val[7]+val[0]+val[1]+val[2]+val[3]+val[4]+val[5],2)
+ return ans;
+}
+
+function generateMkWk() {
+ for (let i = 0; i < key.length; i=i+2) {
+ mk.push(key.slice(i, i + 2));
+ }
+
+ mk = mk.map(item => {
+ return parseInt(item, 16);
+ });
+
+ let tmp = [];
+ for (let i = 0; i < key.length; i += 2) {
+ tmp.push(key.slice(i, i + 2));
+ }
+
+ for (let i = 12; i < 16; i++) {
+ wk.push(parseInt(tmp[i], 16));
+ }
+
+ for (let i = 0; i < 4; i++) {
+ wk.push(parseInt(tmp[i], 16));
+ }
+}
+
+function generateSD() {
+ let tmpD = [s[6], s[5], s[4], s[3], s[2], s[1], s[0]];
+ let tmp2D = tmpD.join('');
+ d.push(tmp2D);
+
+ for (let i = 1; i < 128; i++) {
+ let tmpS = s[i + 2] ^ s[i - 1];
+ tmpD = [tmpS, s[i + 5], s[i + 4], s[i + 3], s[i + 2], s[i + 1], s[i]];
+ tmp2D = tmpD.join('');
+ s.push(tmpS);
+ d.push(tmp2D);
+ }
+ for (let i=0;i {
+ return parseInt(item, 16).toString(2).padStart(8, '0');
+ });
+
+ for (let i=0;i= 0; i--) {
+ tmp_x = [...x];
+ x[0] = tmp_x[1];
+ x[2] = tmp_x[3];
+ x[4] = tmp_x[5];
+ x[6] = tmp_x[7];
+ x[1] = ((tmp_x[2]) - (f1(x[0]) ^ sk[4 * i + 2]) + 256) % 256;
+ x[3] = (tmp_x[4]) ^ (((f0(x[2])) + (sk[4 * i + 1])) % 256);
+ x[5] = ((tmp_x[6]) - (f1(x[4]) ^ sk[4 * i]) + 256) % 256;
+ x[7] = (tmp_x[0]) ^ (((f0(x[6])) + (sk[4 * i + 3])) % 256);
+ }
+}
+
+function final_dec() {
+ let X0 = [...x];
+ let WK = wk.slice().reverse();
+ x[0] = ((X0[0] - WK[0]) + 256) % 256;
+ x[2] = (X0[2] ^ WK[1]);
+ x[4] = ((X0[4] - WK[2]) + 256) % 256;
+ x[6] = (X0[6] ^ WK[3]);
+ x[1] = X0[1];
+ x[3] = X0[3];
+ x[5] = X0[5];
+ x[7] = X0[7];
+}
+
+function main_dec() {
+ generateMkWk();
+ generateSD();
+ generateSK();
+ initial_dec();
+ decryption();
+ final_dec();
+ /*let plaintext = "Plaintext: ";
+ for (let i = 1; i <= 8; i++) {
+ plaintext += (x[x.length - i]).toString(16).padStart(2, '0');
+ }
+ //console.log(plaintext);
+ document.getElementById('decryptionResult').innerHTML = plaintext;*/
+}
+
+function start_dec(){
+ //key="ffeeddccbbaa99887766554433221100";
+ key = document.getElementById('decryptKey').value;
+ key = key.replace(/\s/g, '');
+
+ //let tmp_plainText = "00112233445566771111223344556677";
+ let tmp_cipherText = document.getElementById('cipherText').value;
+ tmp_cipherText = tmp_cipherText.replace(/\s/g, '');
+ //plainText="0011223344556677"
+
+ z=0;y=16;
+ let plaintext = "";
+ for(let i=1;i<(Math.floor(tmp_cipherText.length/16))+1;i++){
+ cipherText=tmp_cipherText.substring(z,y);
+ main_dec();
+ z=z+16;
+ y=y+16;
+ for (let i = 1; i <= 8; i++) {
+ plaintext = plaintext +""+ (x[x.length - i]).toString(16).padStart(2, '0');
+ }
+
+ //restoring global variables
+ mk = [];wk = [];
+ s = [0, 1, 0, 1, 1, 0, 1];
+ d = [];ct = [];
+ sk = new Array(128).fill(0);
+ x = new Array(8).fill(0);
+ cipherText = "";
+ }
+ key = "";
+ console.log(plaintext);
+ plaintext=hexToAscii(plaintext);
+ document.getElementById('decryptionResult').innerHTML = 'Plaintext: '+plaintext;
+}
\ No newline at end of file