#!usrbinpython3 -u from secret import f k i from CryptoPublicKey import ElGamal as c from CryptoUtilnumber import bytes_to_long as t d = k = cconstructk z = 621087549042870328219713812329568850527
This code performs some operations using the ElGamal encryption scheme.
The main parts of the code are as follows:
- The code imports the ElGamal encryption scheme and a function to convert bytes to a long integer.
- The code defines a function
_that takes a string or bytes object, converts it to a long integer, and raises the generatorgof the ElGamal scheme to that integer modulo the primep. This function is used to encrypt messages. - The code defines a function
athat returns the public parameters of the ElGamal scheme: the primep, the generatorg, and the public keyy. - The code defines a list
dto store encrypted messages. - The code defines a function
bthat generates a random integer and encrypts it using the ElGamal scheme. The encrypted integer is added to the listd. - The code defines a function
cthat takes an integer as input and tries to decrypt each element of the listdusing the input integer. If the decrypted value matches a pre-defined valuez, the function returns a secret messagef. Otherwise, the function searches for a message in a pre-defined listithat encrypts to the decrypted value, and returns that message if found. Otherwise, the function returns "not_found". - The code defines a function
Othat prints a menu of options for the user. - The code runs a loop that repeatedly prompts the user to choose an option from the menu, and performs the corresponding operation based on the user's input.
Overall, this code implements a simple "guess the secret message" game using ElGamal encryption. The program generates a random encrypted value and stores it in a list, and the user can try to decrypt the value to reveal the secret message. The program also allows the user to add more encrypted values to the list and to view the public parameters of the ElGamal scheme.
原文地址: https://www.cveoy.top/t/topic/bg7C 著作权归作者所有。请勿转载和采集!