Lab 2 Crypto 22BCE1013
Lab 2 Crypto 22BCE1013
def pad_64(data):
return data.ljust(64, '0')
if __name__ == "__main__":
ip, port = "127.0.0.1", 1234
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((ip, port))
user_data = input("Enter binary string (up to 64 bits): ")
key = "key123"
encrypted = encrypt(user_data, key)
print("Encrypted Output: ", encrypted)
sock.sendall(encrypted.encode())
response = sock.recv(1024)
print("Server Response:", response.decode())
Encryp on Technique Report :
Data Encryp on Standard (DES) : It uses basic permuta ons and bit manipula ons to mimic the
structure of a block cipher. Here are the key steps:
• Padding to 64 Bits - If the input binary string is less than 64 bits, it is padded with zeros on the right
to ensure a xed length of 64 bits.
• Ini al Permuta on (IP) - The input binary string undergoes an ini al permuta on using a
prede ned IP_TABLE, This rearranges the bits based on the table's mapping.
• Bit Reversal - A er the ini al permuta on, the resul ng binary string is reversed. This simple
opera on mimics the complexity introduced in real encryp on algorithms.
• Final Permuta on (FP) - Finally, the reversed string is permuted again using a FP_TABLE, which
rearranges the bits into the nal encrypted format.
• Decryp on - Decryp on reverses the process: apply the nal permuta on, reverse the bits, and
apply the ini al permuta on to retrieve the original plaintext.
Server Code
Purpose - Acts as a receiver and decryptor of messages sent by the client.
1. Socket Ini aliza on:
- A socket is created and bound to the IP `127.0.0.1` (localhost) and port `1234`.
- The server listens for incoming client connec ons.
2. Receiving Data:
- The server accepts a client connec on, receives the encrypted binary string, and decrypts it.
3. Decryp on Process:
- The received binary string is padded to 64 bits.
- The `IP_TABLE` and `FP_TABLE` are used for permuta on and decryp on logic.
4. Response to Client:
- The decrypted message is sent back to the client.
Client Code
Purpose: Encrypts a binary message and sends it to the server.
1. Socket Ini aliza on:
- A socket is created and connected to the server at `127.0.0.1` and port `1234`.
2. User Input:
- The client takes a binary string (up to 64 bits) from the user.
3. Encryp on Process:
- The binary string is padded, permuted using `IP_TABLE`, reversed, and then permuted again using
`FP_TABLE`.
4. Sending Data:
- The encrypted binary string is sent to the server.
5. Receiving Response:
- The client receives the decrypted binary message from the server and displays it
Flow of Execu on
1. Client:
- Encrypts the user-provided binary string.
- Sends the encrypted string to the server.
2. Server:
- Receives the encrypted string.
- Decrypts it back to the original binary message.
- Sends the decrypted message back to the client.
3. Client:
- Receives the decrypted message and displays it.
ti
ti
fi
ti
ti
ti
ti
fi
ti
ti
ti
ti
ti
ti
ti
ft
ti
ti
ti
ti
ti
fi
ti
ti
ti
ti
ti
ti
fi
ti
ti
ti
ti
ti
ti
Output-