The provided Python script is implementing a basic RSA encryption scheme with a twist. It generates a prime number p and ensures that p+6 and p+12 are also prime, assigning these to q and r respectively. The product of p, q, and r forms the RSA modulus n. The public exponent e is set to 2^16 + 1, a common choice in RSA systems. The script then converts a secret flag into a long integer and encrypts it using RSA, resulting in the ciphertext ct. The output file contains the values of n, e, and ct, which are part of the public key and the encrypted message in the RSA encryption scheme.
Final solver.py
To decrypt an RSA-encrypted message. It first factorizes the RSA modulus n into its prime factors p, q, and r using a function called factorize. This function exploits the fact that p, q, and r are close together, which allows for efficient factorization. Then uses these factors to compute the RSA private key and decrypt the ciphertext ct using a function called decrypt. The decrypted message is converted back to bytes and printed out, revealing the original message.
The function first prompts the user for input. It then checks if the length of the input is 40 characters (0x28 in hexadecimal). If the length is correct, it compares segments of the input with predefined strings. If the length is not correct will returns 1.
The function seems to be checking if the input matches a specific format or pattern. The correct input would likely result in the function returning 0.
Base on strcmp they start with the strings t_what_f, t_means}, nd_forge, lactf{no, and orgive_a. Put into correct order.
It first prints a greeting message, then reads a line of input from the user. If the input length is more than 5 characters, it checks for the occurrence of the words “pretty” and “please” in the input. If the word “please” is found, it further checks for the word “flag”. If “flag” is also found and the sum of the occurrences of “pretty” and “please” equals 54 (0x36 in hexadecimal) and the difference between the occurrences of “pretty” and “please” equals -24 (-0x18 in hexadecimal), it prints a message and executes the command cat flag.txt. If these conditions are not met, it prints a refusal message. If the input length is 5 characters or less, it prints a message indicating that the user is being rude. The function returns 0 before it ends.
Final solver.py
In order to exploit. The payload consists of the word “please” repeated 39 times, “pretty” repeated 15 times, and “flag”. The sum of the occurrences of “pretty” and “please” equals 54 (0x36 in hexadecimal) and the difference between the occurrences of “pretty” and “please” equals -24 (-0x18 in hexadecimal). After sending the payload.