diff --git a/C/Cryptography/Hill_Cipher.c b/C/Cryptography/Hill_Cipher.c new file mode 100644 index 000000000..4d162e8c5 --- /dev/null +++ b/C/Cryptography/Hill_Cipher.c @@ -0,0 +1,38 @@ +#include +#include +int main() { + unsigned int a[3][3] = { { 6, 24, 1 }, { 13, 16, 10 }, { 20, 17, 15 } }; + unsigned int b[3][3] = { { 8, 5, 10 }, { 21, 8, 21 }, { 21, 12, 8 } }; + int i, j; + unsigned int c[20], d[20]; + char msg[20]; + int determinant = 0, t = 0; + ; + printf("Enter plain text\n "); + scanf("%s", msg); + for (i = 0; i < 3; i++) { + c[i] = msg[i] - 65; + printf("%d ", c[i]); + } + for (i = 0; i < 3; i++) { + t = 0; + for (j = 0; j < 3; j++) { + t = t + (a[i][j] * c[j]); + } + d[i] = t % 26; + } + printf("\nEncrypted Cipher Text :"); + for (i = 0; i < 3; i++) + printf(" %c", d[i] + 65); + for (i = 0; i < 3; i++) { + t = 0; + for (j = 0; j < 3; j++) { + t = t + (b[i][j] * d[j]); + } + c[i] = t % 26; + } + printf("\nDecrypted Cipher Text :"); + for (i = 0; i < 3; i++) + printf(" %c", c[i] + 65); + return 0; +} \ No newline at end of file diff --git a/README.md b/README.md index 562bfec95..69133466b 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ | 3. | Columnar Transposition Cipher | [C](https://github.com/Kumar-laxmi/Algorithms/blob/main/C/Cryptography/ColumnarTranspositionCipher.c), [C++](https://github.com/Kumar-laxmi/Algorithms/blob/main/C%2B%2B/Cryptography/ColumnarTranspositionCipher.cpp), [Java](https://github.com/Kumar-laxmi/Algorithms/blob/main/Java/Cryptography/ColumnarTranspositionCipher.java), [Python](https://github.com/Kumar-laxmi/Algorithms/blob/main/Python/Cryptography/ColumnarTranspositionCipher.py) | | 4. | Diffie - Hellman Algorithm | [Python](https://github.com/Kumar-laxmi/Algorithms/blob/main/Python/Cryptography/DiffieHellman.py) | | 5. | Elgamal Cryptosystem | [C](https://github.com/Kumar-laxmi/Algorithms/blob/main/C/Cryptography/Elgamal.c), [C++](https://github.com/Kumar-laxmi/Algorithms/blob/main/C%2B%2B/Cryptography/Elgamal.cpp), [Java](https://github.com/Kumar-laxmi/Algorithms/blob/main/Java/Cryptography/Elgamal.java), [Python](https://github.com/Kumar-laxmi/Algorithms/blob/main/Python/Cryptography/Elgamal.py) | -| 6. | Hill Cipher | [C++](https://github.com/Kumar-laxmi/Algorithms/blob/main/C%2B%2B/Cryptography/HillCipher.cpp), [Java](https://github.com/Kumar-laxmi/Algorithms/blob/main/Java/Cryptography/HillCipher.java), [Python](https://github.com/Kumar-laxmi/Algorithms/blob/main/Python/Cryptography/HillCipher.py) | +| 6. | Hill Cipher | [C](https://github.com/Kumar-laxmi/Algorithms/blob/main/C/Cryptography/Hill_Cipher.c), [C++](https://github.com/Kumar-laxmi/Algorithms/blob/main/C%2B%2B/Cryptography/HillCipher.cpp), [Java](https://github.com/Kumar-laxmi/Algorithms/blob/main/Java/Cryptography/HillCipher.java), [Python](https://github.com/Kumar-laxmi/Algorithms/blob/main/Python/Cryptography/HillCipher.py) | | 7. | Homophonic Substitution | [C](https://github.com/Kumar-laxmi/Algorithms/blob/main/C/Cryptography/homophonic_substitution.c), [C++](https://github.com/Kumar-laxmi/Algorithms/blob/main/C%2B%2B/Cryptography/homophonic_substitution.cpp), [Java](https://github.com/Kumar-laxmi/Algorithms/blob/main/Java/Cryptography/HomophonicSubstitution.java), [Python](https://github.com/Kumar-laxmi/Algorithms/blob/main/Python/Cryptography/homophonic_Substitution.py) | | 8. | Morse Code | [C](https://github.com/Kumar-laxmi/Algorithms/blob/main/C/Cryptography/MorseCodeConvortor.c), [C++](https://github.com/Kumar-laxmi/Algorithms/blob/main/C%2B%2B/Cryptography/MorseCodeConvotor.cpp), [Java](https://github.com/Kumar-laxmi/Algorithms/blob/main/Java/Cryptography/MorseCodeConverter.java), [Python](https://github.com/Kumar-laxmi/Algorithms/blob/main/Python/Cryptography/MorseCodeConvortor.py) | | 9. | Playfair Cipher | [C](https://github.com/Kumar-laxmi/Algorithms/blob/main/C/Cryptography/playfair_cipher.c), [C++](https://github.com/Kumar-laxmi/Algorithms/blob/main/C%2B%2B/Cryptography/playfair_cipher.cpp), [Java](https://github.com/Kumar-laxmi/Algorithms/blob/main/Java/Cryptography/PlayfairCipher.java), [Python](https://github.com/Kumar-laxmi/Algorithms/blob/main/Python/Cryptography/playfair_cipher.py) |