-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from serengil/feat-task-0712-encrypting-floats
float encryption support added
- Loading branch information
Showing
5 changed files
with
63 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from lightphe.commons.logger import Logger | ||
|
||
logger = Logger() | ||
|
||
# pylint: disable=no-else-return | ||
|
||
|
||
def parse_int(value, modulo) -> int: | ||
if isinstance(value, int) and value >= 0: | ||
return value | ||
elif isinstance(value, int) and value < 0: | ||
return value % modulo | ||
elif isinstance(value, float) and value >= 0: | ||
decimal_places = len(str(value).split(".")[1]) | ||
scaling_factor = 10**decimal_places | ||
integer_value = int(value * scaling_factor) | ||
logger.debug(f"{integer_value}*{scaling_factor}^-1 mod {modulo}") | ||
return integer_value * pow(scaling_factor, -1, modulo) | ||
elif isinstance(value, float) and value < 0: | ||
# TODO: think and implement this later | ||
raise ValueError("Case constant float and negative not implemented yet") | ||
else: | ||
raise ValueError(f"Unimplemented case for constant type {type(value)}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters