Lab6 F
Lab6 F
Date :
AIM : Write a program to Implement Symmetric key cryptography.
APPARATUS : Scilab
THEORY :
Symmetric Key Cryptography
1. Definition: Symmetric key cryptography is a type of encryption where the same key is used for both
encryption and decryption of data. It is one of the two main types of cryptography, the other being
asymmetric cryptography. In symmetric cryptography, both the sender and the receiver must have
access to the same secret key, which must be kept private.
2. How It Works:
• Encryption: The plaintext message is transformed into ciphertext using the secret key and a
chosen encryption algorithm.
• Decryption: The ciphertext is transformed back into plaintext using the same secret key and
the corresponding decryption algorithm.
1.Encryption:
2.Decryption:
• XOR the ciphertext with the same key used for encryption. Due to the self-inverse property of
XOR, this operation restores the original plaintext.
3. Algorithm Steps
1.Convert Plaintext and Key:
• Convert the plaintext and key into their binary or ASCII values.
• XOR each byte (or bit) of the plaintext with the corresponding byte (or bit) of the key. If the
key is shorter, wrap around and repeat the key as necessary.
3.Output Ciphertext:
• Convert the result back to characters or binary as needed.
4.Decrypt Ciphertext:
• Apply the same XOR operation with the same key to the ciphertext to retrieve the original
plaintext.
CODE :
// Function for XOR encryption/decryption function
result=xor_cipher(data, key)
data = ascii(data);
key = ascii(key);
key_length = length(key);
data_length = length(data);
0."); end
for i = 1:data_length
end
result = char(result');
disp("--------------------------------------------------")
disp("--------------------------------------------------")
disp("Decrypted Message: " + decrypted_message)
OUTPUT :
CONCLUSIONS :
It offers efficient and fast encryption but requires secure key exchange between the parties. Its
simplicity makes it suitable for many applications, though it lacks the scalability of public-key
systems. For secure communication, careful management and protection of the shared key are
essential.