Aim: Write a C program that contains a string (char pointer) with a value ‘Hello world’. The program should XOR each character in this string with 0 and displays the result. Theory: XOR Encryption is an encryption method used to encrypt data and is hard to crack by brute-force method, i.e generating random encryption keys to match with the correct one. The concept of implementation is to first define XOR – encryption key and then to perform XOR operation of the characters in the String with this key which you want to encrypt. To decrypt the encrypted characters we have to perform XOR operation again with the defined key. Here we are encrypting the entire String. Aim: Write a C program that contains a string (char pointer) with a value ‘Hello world’. The program should AND or and XOR each character in this string with 127 and display the result. Theory: AND When we use the AND operator, we are effectively saying, if the first argument and the second argument are true, then the result is true, or 1. Otherwise the result is false, or 0. 0 AND 0 = 0 1 AND 0 = 0 0 AND 1 = 0 1 AND 1 = 1AND is represented by the ampersand - 1 & 1 = 1 OR Now the OR operator is saying, if the first argument or the second argument are true, then the result is true. 0 OR 0 = 0 1 OR 0 = 1 0 OR 1 = 1 1 OR 1 = 1OR is represented by the vertical bar (pipe) - 1 | 1 = 1 XOR Lastly, the XOR (exclusive OR) operator is saying, if either input is true, then the result is true, but if both inputs are true, then the result is false. Another way to say it is, if one, but not both arguments are true, then the result is true. Or, we could say, if the number of true inputs is odd, then the result will be true. You choose. 0 XOR 0 = 0 1 XOR 0 = 1 0 XOR 1 = 1 1 XOR 1 = 0XOR is represented by the upwards caret - 1 ^ 1 = 1 Before we finish let’s use the XOR operator on a set of eight digits, a byte. 01011000 XOR 10111001 => 11100001 If you’ve ever worked with circuits, transistors, computers, code or electricity, you might see how useful these three operators can be. Aim: Write a Java program to perform encryption and decryption using the Ceaser Cipher algorithm Theory: Encryption is the process by which a readable message is converted to an unreadable form to prevent unauthorized parties from reading it. Decryption is the process of converting an encrypted message back to its original (readable) format. The original message is called the plaintext message . The encrypted message is called the ciphertext message The Ceaser Cipher technique is one of the earliest and simplest methods of encryption technique. It’s simply a type of substitution cipher, i.e., each letter of a given text is replaced by a letter with a fixed number of positions down the alphabet. For example, with a shift of 1, A would be replaced by B, B would become C, and so on. The method is apparently named after Julius Caesar, who apparently used it to communicate with his officials. Thus, to cipher a given text we need an integer value, known as a shift which indicates the number of positions each letter of the text has been moved down. The encryption can be represented using modular arithmetic by first transforming the letters into numbers, according to the scheme, A = 0, B = 1,..., Z = 25. Encryption of a letter by a shift n can be described mathematically as. (Encryption Phase with shift n) (Decryption Phase with shift n) Examples: Text: ABCDEFGHIJKLMNOPQRSTUVWXYZ Shift: 23 Cipher: XYZABCDEFGHIJKLMNOPQRSTUVW Text: ATTACKATONCE Shift: 4 Cipher: EXXEGOEXSRG Aim: Write a Java program to perform encryption and decryption using the Substitution cipher algorithm Theory: Substitution cipher, any character of plain text from the given fixed set of characters is substituted by some other character from the same set depending on a key. For example with a shift of 1, A would be replaced by B, B would become C, and so on. Mathematical representation The encryption can be represented using modular arithmetic by first transforming the letters into numbers, according to the scheme, A = 0, B = 1,..., Z = 25. Encryption of a letter by a shift n can be described mathematically as. Examples: Plain Text: I am studying Data Encryption Key: 4 Output: M eq wxyhCmrk Hexe IrgvCtxmsr Plain Text: ABCDEFGHIJKLMNOPQRSTUVWXYZ Key: 4 Output: EFGHIJKLMNOPQRSTUVWXYZabcd Algorithm for Substitution Cipher: Input: ● A String of both lower and upper case letters, called PlainText. ● An Integer denoting the required key. Procedure: ● Create a list of all the characters. ● Create a dictionary to store the substitution for all characters. ● For each character , transform the given character as per the rule, depending on whether we’re encrypting or decrypting the text. ● Print the new string generated. Aim: Write a Java program to perform encryption and decryption using the Hill cipher algorithm Theory: Hill cipher is a polygraphic substitution cipher based on linear algebra.Each letter is represented by a number modulo 26. Often the simple scheme A = 0, B = 1, ..., Z = 25 is used, but this is not an essential feature of the cipher. To encrypt a message, each block of n letters (considered as an n-component vector) is multiplied by an invertible n × n matrix, against modulus 26. To decrypt the message, each block is multiplied by the inverse of the matrix used for encryption. The matrix used for encryption is the cipher key, and it should be chosen randomly from the set of invertible n × n matrices (modulo 26). Examples: Input : Plaintext: ACT Key: GYBNQKURP Output : Ciphertext: POH Input : Plaintext: GFG Key: HILLMAGIC Output : Ciphertext: SWK Encryption We have to encrypt the message ‘ACT’ (n=3).The key is ‘GYBNQKURP’ which can be written as the nxn matrix: The message ‘ACT’ is written as vector: The enciphered vector is given as: which corresponds to ciphertext of ‘POH’ Decryption To decrypt the message, we turn the ciphertext back into a vector, then simply multiply by the inverse matrix of the key matrix (IFKVIVVMI in letters).The inverse of the matrix used in the previous example is: For the previous Ciphertext ‘POH’: Aim: Write a C/JAVA program to implement the DES algorithm logic. Theory: Data encryption standard (DES) has been found vulnerable to very powerful attacks and therefore, the popularity of DES has been found slightly on the decline. DES is a block cipher and encrypts data in blocks of size of 64 bits each, which means 64 bits of plain text go as the input to DES, which produces 64 bits of ciphertext. The same algorithm and key are used for encryption and decryption, with minor differences. The key length is 56 bits . The basic idea is shown in the figure: Let us now discuss the broad-level steps in DES. ● In the first step, the 64-bit plain text block is handed over to an initial Permutation (IP) function. ● The initial permutation is performed on plain text. ● Next, the initial permutation (IP) produces two halves of the permuted block; saying Left Plain Text (LPT) and Right Plain Text (RPT). ● Now each LPT and RPT go through 16 rounds of the encryption process. ● In the end, LPT and RPT are rejoined and a Final Permutation (FP) is performed on the combined block ● The result of this process produces 64-bit ciphertext. The key transformation process compresses the 56-bit key to 48 bits. Then the expansion permutation process expands the 32-bit RPT to 48-bits . Now the 48-bit key is XOR with 48-bit RPT and the resulting output is given to the next step, which is the S-Box substitution Aim: Write a C/JAVA program to implement the Blowfish algorithm logic. Theory: Blowfish is an encryption technique designed by Bruce Schneier in 1993 as an alternative to DES Encryption Technique. It is significantly faster than DES and provides a good encryption rate with no effective cryptanalysis technique found to date. It is one of the first, secure block cyphers not subject to any patents and hence freely available for anyone to use. 1. blockSize : 64-bits 2. keySize : 32-bits to 448-bits variable size 3. number of subkeys : 18 [P-array] 4. number of rounds : 16 5. number of substitution boxes : 4 [each having 512 entries of 32-bits each] Blowfish Encryption Algorithm The entire encryption process can be elaborated as: Decryption The decryption process is similar to that of encryption and the subkeys are used in reverse{P[17] – P[0]}. The entire decryption process can be elaborated as: Aim: Write a C/JAVA program to implement the Rijndael algorithm logic. Theory: Advanced Encryption Standard (AES) is a specification for the encryption of electronic data established by the U.S National Institute of Standards and Technology (NIST) in 2001. AES is widely used today as it is a much stronger than DES and triple DES despite being harder to implement. Points to remember ● AES is a block cipher. ● The key size can be 128/192/256 bits. ● Encrypts data in blocks of 128 bits each. That means it takes 128 bits as input and outputs 128 bits of encrypted cipher text as output. AES relies on substitution-permutation network principle which means it is performed using a series of linked operations which involves replacing and shuffling of the input data. Working of the cipher : AES performs operations on bytes of data rather than in bits. Since the block size is 128 bits, the cipher processes 128 bits (or 16 bytes) of the input data at a time. The number of rounds depends on the key length as follows : ● 128 bit key – 10 rounds ● 192 bit key – 12 rounds ● 256 bit key – 14 rounds Aim: Write the RC4 logic in Java Using Java cryptography; encrypt the text ‘Hello world’ using Blowfish. Create your own key using Java key tool. Theory: RC4 is a stream cipher and variable-length key algorithm. This algorithm encrypts one byte at a time (or larger units at a time). A key input is a pseudorandom bit generator that produces a stream 8-bit number that is unpredictable without knowledge of input key, The output of the generator is called key-stream, is combined one byte at a time with the plaintext stream cipher using X-OR operation. Example: RC4 Encryption 10011000 ? 01010000 = 11001000 RC4 Decryption 11001000 ? 01010000 = 10011000 Pseudo random generation algorithm (Stream Generation): Once the vector S is initialized, the input key will not be used. In this step, for each S[i] algorithm swap it with another byte in S according to a scheme dictated by the current configuration of S. After reaching S[255] the process continues, starting from S[0] again j = 0; for i = 0 to 255 do { j = (j + S[i] + T[i])mod 256; Swap(S[i], S[j]); } Aim: Write a Java program to implement RSA algorithm. Theory: RSA algorithm is an asymmetric cryptography algorithm. Asymmetric actually means that it works on two different keys i.e. Public Key and Private Key. As the name describes that the Public Key is given to everyone and the Private key is kept private. RSA algorithm uses the following procedure to generate public and private keys: Select two large prime numbers, p and q. Multiply these numbers to find n = p x q, where n is called the modulus for encryption and decryption. Choose a number e less than n, such that n is relatively prime to (p - 1) x (q -1). It means that e and (p - 1) x (q - 1) have no common factor except 1. Choose "e" such that 1<e < φ (n), e is prime to φ (n), gcd (e,d(n)) =1 If n = p x q, then the public key is <e, n>. A plaintext message m is encrypted using public key <e, n>. To find ciphertext from the plain text following formula is used to get ciphertext C. C = me mod n Here, m must be less than n. A larger message (>n) is treated as a concatenation of messages, each of which is encrypted separately. To determine the private key, we use the following formula to calculate the d such that: De mod {(p - 1) x (q - 1)} = 1 Or De mod φ (n) = 1 The private key is <d, n>. A ciphertext message c is decrypted using private key <d, n>. To calculate plain text m from the ciphertext c following formula is used to get plain text m. m = cd mod n Aim: Calculate the message digest of a text using the SHA-1 algorithm in JAVA. Theory: SHA-1 or Secure Hash Algorithm 1 is a cryptographic hash function which takes an input and produces a 160-bit (20-byte) hash value. This hash value is known as a message digest. This message digest is usually then rendered as a hexadecimal number which is 40 digits long. It is a U.S. Federal Information Processing Standard and was designed by the United States National Security Agency. SHA-1 is now considered insecure since 2005. Some of the protocols that use SHA-1 include: ● Transport Layer Security (TLS) ● Secure Sockets Layer (SSL) ● Pretty Good Privacy (PGP) ● Secure Shell (SSH) ● Secure/Multipurpose Internet Mail Extensions (S/MIME) ● Internet Protocol Security (IPSec) SHA-1 is commonly used in cryptographic applications and environments where the need for data integrity is high. It is also used to index hash functions and identify data corruption and checksum errors. Aim: Calculate the message digest of a text using the MD5 algorithm in JAVA. Theory: MD5 is a cryptographic hash function algorithm that takes the message as input of any length and changes it into a fixed-length message of 16 bytes. MD5 algorithm stands for the message-digest algorithm . MD5 was developed as an improvement of MD4, with advanced security purposes. The output of MD5 (Digest size) is always 128 bits. MD5 was developed in 1991 by Ronald Rivest. Use Of MD5 Algorithm: ● It is used for file authentication. ● In a web application, it is used for security purposes. e.g. Secure password of users etc. ● Using this algorithm, We can store our password in 128 bits format. MD5 Algorithm