Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions damgard_jurik/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ def encrypt_list(self, m_list: List[int]) -> List[EncryptedNumber]:
"""
return [self.encrypt(m) for m in m_list]

def encrypt_string(self, m: str) -> List[EncryptedNumber]:
"""Encrypts a string using it's ASCII values.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"using its ASCCII values" isn't exactly correct, because ord() accommodates unicode characters. (also "its" is misspelled.)


:param m: The plaintext string to be encrypted.
:return: A list containing an EncryptedNumber for each character ASCII value in `m`.
"""
return self.encrypt_list(map(ord, m))

def __eq__(self, other: Any) -> bool:
"""Returns whether this PublicKey is equal to `other`.

Expand Down Expand Up @@ -354,6 +362,14 @@ def decrypt_list(self, c_list: List[EncryptedNumber]) -> List[int]:
"""
return [self.decrypt(c) for c in c_list]

def decrypt_string(self, c_list: List[EncryptedNumber]) -> str:
"""Decrypts each number in a list as a character in a string.

:param c_list: A list of EncryptedNumbers to be decrypted.
:return: A string containing a character for each decrypted EncryptedNumber in `c_list`.
"""
return "".join([chr(self.decrypt(c)) for c in c_list])


def keygen(n_bits: int = 64,
s: int = 1,
Expand Down