katana.units.crypto.affine — Affine Cipher

Attempt to decrypt a target with the classic Affine cipher.

You can read more about the Affine cipher here: https://en.wikipedia.org/wiki/Affine_cipher

This unit inherits from the katana.unit.NotEnglishAndPrintableUnit class, as we can expect the data to still be printable characters (letters, numbers and punctuation) but not readable English.

You can supply and customize the given A and B values as well as the alphabet to be used in the Affine cipher operation, though by default this will bruteforce and use the range provided with the English alphabet, letters A-Z.

class katana.units.crypto.affine.Unit(manager: katana.manager.Manager, target: katana.target.Target)

Bases: katana.unit.NotEnglishAndPrintableUnit, katana.units.crypto.CryptoUnit

BLOCKED_GROUPS = ['crypto']

This unit does not recurse into other Crypto units because that might spiral into a disaster.

GROUPS = ['crypto', 'affine']

These are “tags” for a unit. Considering it is a Crypto unit, “crypto” is included, as well as the name of the unit, “affine”.

PRIORITY = 65

Priority works with 0 being the highest priority, and 100 being the lowest priority. 50 is the default priorty. This unit has a somewhat lower priority due to how uncommon this is within CTFs.

RECURSE_SELF = False

This unit should not recurse into itself. That could spiral in to an infinite loop.

enumerate() → Generator[Any, None, None]

Yield unit cases. This will check if any given A or B values are supplied to the unit. If a value is not supplied, it will use all numbers up the length of the alphabet (which can also be supplied), by default, the English letters A-Z. The corresponding value will be the greatest common denominator between that in the length, as that is the only correspondent value that is mathematically required for the Affine cipher to work.

Returns:Generator of target cases, in this case a tuple of A and B values.
evaluate(case: Any) → None

Evaluate the target. This will perform

Parameters:case – A case returned by enumerate, in this case a tuple of A and B values.
Returns:None. This function should not return any data.
katana.units.crypto.affine.affine(c: int, a: int, b: int, alphabet: bytes) → str

Perform the affine cipher for a single letter.

C:An integer value for the given letter (its location within the alphabet)
A:An integer value for the A value used in the Affine cipher operation.
B:An integer value for the B value used in the Affine cipher operation.
Alphabet:A bytes string for the supplied alphabet.