X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=pygost%2Futils.py;h=632eb2f2de6dfc58e4fb87c6433179c8982a4f61;hb=9af4461c6af50f9cf83030867e7054d1f6311b32;hp=3844e1a429f43e455ed7f391a21a495306ae6b2e;hpb=34c9c9a4f95eecfee75fc36d75d2ee45d1054a25;p=pygost.git diff --git a/pygost/utils.py b/pygost/utils.py index 3844e1a..632eb2f 100644 --- a/pygost/utils.py +++ b/pygost/utils.py @@ -1,11 +1,10 @@ # coding: utf-8 # PyGOST -- Pure Python GOST cryptographic functions library -# Copyright (C) 2015-2016 Sergey Matveev +# Copyright (C) 2015-2021 Sergey Matveev # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# the Free Software Foundation, version 3 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -24,7 +23,7 @@ xrange = range if version_info[0] == 3 else xrange def strxor(a, b): - """ XOR of two strings + """XOR of two strings This function will process only shortest length of both strings, ignoring remaining one. @@ -53,20 +52,20 @@ def hexenc(data): def bytes2long(raw): - """ Deserialize big-endian bytes into long number + """Deserialize big-endian bytes into long number :param bytes raw: binary string - :return: deserialized long number + :returns: deserialized long number :rtype: int """ return int(hexenc(raw), 16) def long2bytes(n, size=32): - """ Serialize long number into big-endian bytestring + """Serialize long number into big-endian bytestring :param long n: long number - :return: serialized bytestring + :returns: serialized bytestring :rtype: bytes """ res = hex(int(n))[2:].rstrip("L") @@ -74,14 +73,14 @@ def long2bytes(n, size=32): res = "0" + res s = hexdec(res) if len(s) != size: - s = (size - len(s)) * b'\x00' + s + s = (size - len(s)) * b"\x00" + s return s def modinvert(a, n): - """ Modular multiplicative inverse + """Modular multiplicative inverse - :return: inverse number. -1 if it does not exist + :returns: inverse number. -1 if it does not exist Realization is taken from: https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm