This code performs some operations using the ElGamal encryption scheme.

The main parts of the code are as follows:

  1. The code imports the ElGamal encryption scheme and a function to convert bytes to a long integer.
  2. The code defines a function _ that takes a string or bytes object, converts it to a long integer, and raises the generator g of the ElGamal scheme to that integer modulo the prime p. This function is used to encrypt messages.
  3. The code defines a function a that returns the public parameters of the ElGamal scheme: the prime p, the generator g, and the public key y.
  4. The code defines a list d to store encrypted messages.
  5. The code defines a function b that generates a random integer and encrypts it using the ElGamal scheme. The encrypted integer is added to the list d.
  6. The code defines a function c that takes an integer as input and tries to decrypt each element of the list d using the input integer. If the decrypted value matches a pre-defined value z, the function returns a secret message f. Otherwise, the function searches for a message in a pre-defined list i that encrypts to the decrypted value, and returns that message if found. Otherwise, the function returns "not_found".
  7. The code defines a function O that prints a menu of options for the user.
  8. 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.

#!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

原文地址: https://www.cveoy.top/t/topic/bg7C 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录