PK!ݤցdamm32/__init__.py""" Damm32 Library. A python implementation of the Damm algorithm, in base 32. """ from .checksum import Damm32 # noqa: F401 PK!pdamm32/checksum.py"""This file contains checksum implementations.""" from typing import List Digit = int DigitList = List[Digit] Alphabet = List[str] class BadCharacterException(ValueError): """An invalid character was found in your input.""" pass class BadAlphabetException(Exception): """That alphabet is of the wrong length or has duplicate characters.""" pass class Damm32: """Implementation of the Damm algorithm.""" BASE_SIZE = 32 ALPHABET = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7'] # noqa: E501 def __init__(self, alphabet: Alphabet = ALPHABET) -> None: if len(set(alphabet)) != 32 or len(alphabet) != 32: raise BadAlphabetException def _calculate_from_digits(self, digits: DigitList) -> Digit: mask = 37 checkdigit = 0 for digit in digits: checkdigit ^= digit checkdigit <<= 1 if checkdigit >= Damm32.BASE_SIZE: checkdigit ^= mask return checkdigit def _to_digits(self, word: str) -> DigitList: if type(word) is not str: raise TypeError word = word.upper() try: dl = [] for i in word: dl.append(Damm32.ALPHABET.index(i)) return dl except ValueError: pass raise BadCharacterException def _to_word(self, digits: DigitList) -> str: word = "" for i in digits: word += Damm32.ALPHABET[i] return word def calculate(self, word: str) -> str: """Calculate the check digit for a string.""" digits = self._to_digits(word) checkdigit = self._calculate_from_digits(digits) return Damm32.ALPHABET[checkdigit] def verify(self, word: str) -> bool: """Verify that a string contains a valid check digit.""" return self.calculate(word) == Damm32.ALPHABET[0] PK! 9,,damm32-0.0.3.dist-info/LICENSEMIT License Copyright (c) 2018 Dan Trickey Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HڽTUdamm32-0.0.3.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!Ha1damm32-0.0.3.dist-info/METADATAT]s7}ׯMl8nqR8md*iq5n:尺q+y⽏2DγonrnnβlJcxF0_U*eF:@*$\c  *+% 3v -*Rqoѩ\g™fJHv`Jdzpocjn2ؽTA޼t_aav&Ǩ6Jb¶ Fp0eNg|Eȝ[xbͥ6}>np$ q-qz i7GG\ןRlһ U?}-ʓzg[Tߩ2VFWˉ Bs~Q[+l~G[)1UZ^WczƮ*冗:uA%(B|-cm: /߾1S2m2"ANx*(@ o\و%Զ4QE݅'l2Jڹ-4 8yN2kAE.aB96^cZT0D&_k r^*_yUѴ4;HMYc&;RF+eW|akb#{Qr+,B;+ l\^jLf*,,0u֪㪋p (<ƅ, )v44j6v t!4=s-hϰQ"ͻUMl4اMZZD2nQX4S$R g/#C#ي-9d|҅+ 5;?L ~&`FpK`N+=#o|"`@0$xCpAsK?PK!H (damm32-0.0.3.dist-info/RECORDurC@{eZd8 '.;B<}mfz_քPFGBnC!yvm\7}HssNۏ3W(pNh$@ uUNyUpoMeLh>L )Xb” '`8߃.dvPWqt9ұgS3yX]R]6 ĕ Fy;tJջchs͛h6is(GЎsP$LFDKaɎsbGK@P$b V?PK!ݤցdamm32/__init__.pyPK!pdamm32/checksum.pyPK! 9,,damm32-0.0.3.dist-info/LICENSEPK!HڽTU0 damm32-0.0.3.dist-info/WHEELPK!Ha1 damm32-0.0.3.dist-info/METADATAPK!H (\damm32-0.0.3.dist-info/RECORDPK