Structures

Decryption

Class to group information about a decryption.

Todo

Possibly add more functionality to this class * Equality checking * Formatted plaintext (added spaces) Once there is evidence these things are needed, I will implement them

class lantern.structures.decryption.Decryption(plaintext, key, score)

A decryption object, composed of plaintext, a score and the key.

Example

>>> decryption = Decryption("example", "key", -10)
>>> decryption.plaintext
example
>>> decryption.key
key
>>> decryption.score
-10
__init__(plaintext, key, score)
Parameters:
  • plaintext – The decrypted ciphertext
  • key – The key which resulted in this decryption
  • score – The score of this decryption
__lt__(other)

Compare decryptions with other decryptions by score.

Parameters:other – Object to compare with
Returns:True if self is less than other, else False

DynamicDict

Class to dynamically create attributes only when they are needed.

Todo

This needs some more functionality. Specifically it doesnt behave like a proper dictionary

class lantern.structures.dynamicdict.DynamicDict(builders={})

Dictionary which builds values when they are accessed for the first time.

Example

>>> ngrams = DynamicDict({
...     'trigrams': lambda: load_ngrams('trigrams'),
...     'quadgrams': lambda: load_ngrams('quadgrams')
... })

Since trigrams and quadgrams are large files, its expensive to load them in if theyre not needed. Using the DynamicDict ensures they are only loaded when they are accessed for the first time.

__getattr__(name)

Attempt to build values that are not already created.

__init__(builders={})

Instantiate dict with mapping of keys to builders.

Parameters:builders (dict) – key to function mapping