lab6_support

.py

School

College of DuPage *

*We aren’t endorsed by this school

Course

1B

Subject

Computer Science

Date

Feb 20, 2024

Type

py

Pages

1

Uploaded by Caleb8793

Report
# Chat Encryption Helper - ch9_crypto_chat.py import os, base64, json #from Crypto.Cipher import PKCS1_OAEP, AES #from Crypto.PublicKey import RSA, ECC from binascii import hexlify, unhexlify from base64 import b64encode, b64decode # encryption method used by all calls def encrypt(message, usePKI, useDH, dhSecret): em=cipherEncrypt(message, dhSecret, 1) return em # decryption method used by all calls def decrypt(message, usePKI, useDH, dhSecret): dm=cipherEncrypt(message, dhSecret, -1) return dm # decrypt using RSA (for future reference, not needed for this homework) #def decrypt_rsa(ciphertext): # return ciphertext # encrypt using RSA (for future reference, not needed for this homework) #def encrypt_rsa(message): # return message # check client commands (for future reference, not needed for this homework) def check_client_command(data): return 1 # check server commands (for future reference, not needed for this homework) def check_server_command(data): return 1 def reversed_string(a_string): return a_string[::-1] def cipherEncrypt(inputText, N, D): # shift a character by N positions in the specified direction def shift(char, N, D): if char.isalpha(): start = 65 if char.isupper() else 97 char_code = ord(char) shifted_char_code = start + ((char_code - start + D * N) % 26) return chr(shifted_char_code) elif char.isdigit(): start = 48 char_code = ord(char) shifted_char_code = start + ((char_code - start + D * N) % 10) return chr(shifted_char_code) return char # reverse the input text reversed_text = inputText[::-1] # encrypt the reversed text encrypted_text = "".join(shift(char, N, D) for char in reversed_text) return encrypted_text
Discover more documents: Sign up today!
Unlock a world of knowledge! Explore tailored content for a richer learning experience. Here's what you'll get:
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help