katana.units.crypto.rsa — Attempt to solve RSA

RSA decryptor

This takes arguments “e”, “n”, “q”, “p”, “dq”, “dp”, “d”, “c”, “phi”, though they will potentially be automatically decoded by the program if a plaintext file is supplied.

class katana.units.crypto.rsa.Unit(*args, **kwargs)

Bases: katana.unit.NotEnglishUnit

BLOCKED_GROUPS = ['crypto']

These are tags for groups to not recurse into. Recursing into other crypto units would be silly.

GROUPS = ['crypto', 'rsa']

These are “tags” for a unit. Considering it is a Crypto unit, “crypto” is included, and the name of the unit, “rsa”.

PRIORITY = 60

Priority works with 0 being the highest priority, and 100 being the lowest priority. 50 is the default priorty. This unit has a slightly lower priority.

RECURSE_SELF = False

Do not recurse into self

evaluate(case: Any) → None

Evaluate the target.

Parameters:case – A case returned by enumerate. For this unit, the enumerate function is not used.
Returns:None. This function should return any data.
katana.units.crypto.rsa.contfrac_to_rational(frac: list)

This function is used for the Weiner’s Little D attack.

Converts a finite continued fraction [a0, ..., an] to an x/y rational.

katana.units.crypto.rsa.convergents_from_contfrac(frac: list) → list

This function is used for the Weiner’s Little D attack.

Computes the list of convergents using the list of partial quotients

Parameters:frac – Fractions represented by a list
Returns:A list of convergents
katana.units.crypto.rsa.egcd(a, b)

This function is used for the Weiner’s Little D attack.

Determines the Euclidean Greatest Common Denominator between given values.

Parameters:
  • a – One value to be used to find the GCD for.
  • b – Another value to be used to find the GCD for.
Returns:

katana.units.crypto.rsa.find_cube_root(n)

This function is used for the Cube Root attack.

Determines the cube root of a number.

Parameters:n – The number to determine the cube root of.
Returns:The resulting cube root.
katana.units.crypto.rsa.find_variables(text)

This is used to detect variables in a given file, or handle a given pubkey.

Parameters:text – The string to pull the variables from.
Returns:A Generator for an RSA letter variable and its value.
katana.units.crypto.rsa.isqrt(n)

This function is used for the Weiner’s Little D attack.

Determines the integer square root of a nunber.

Parameters:n – The number to determine the integer square root of.
Returns:The resulting integer square root.
katana.units.crypto.rsa.mod_inv(a, m)

This function is used for the Weiner’s Little D attack.

Deterine the modular inverse, given a base and the modulus.

Parameters:
  • a – The base to use for the modular inverse operation.
  • m – The modulus to use for the modular inverse operation.
Returns:

An integer as the result of the modular inverse.

katana.units.crypto.rsa.parse_int(given)

This function will parse out a Python value regardless of the representation a number is given in the provided string. It will detect hex or an integer form.

Parameters:given – The string information that potentially includes a number.
Returns:The Python integer value found.
katana.units.crypto.rsa.rational_to_contfrac(x: int, y: int) → list

This function is used for the Weiner’s Little D attack.

Converts a rational x/y fraction into a list of partial quotients [a0, …, an]

Parameters:
  • x – The numerator of the provided fraction.
  • y – The denominator of the provided fraction.
Returns:

a list of partial quotients.

katana.units.crypto.rsa.weiners_little_d(e, n)

This function is used for the Weiner’s Little D attack.

Actually

Parameters:
  • e – The RSA e-value (exponent).
  • n – The RSA N-value (modulus).
Returns:

The determined RSA d-value (private key) after the Weiner’s Little D attack.