SHARE
TWEET

Untitled

a guest Mar 26th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from math import gcd as bltin_gcd
  2. class T52:
  3.     def __init__(self, a: int, b: int, alfabet: str):
  4.         if len(alfabet) != len(set(alfabet)):
  5.             raise AssertionError("alfabet bevat herhaalde symbolen")
  6.         if bltin_gcd(a, len(alfabet)) != 1:
  7.             raise AssertionError(f"{a} en {len(alfabet)} zijn niet copriem")
  8.         self.a = a
  9.         self.b = b
  10.         self.alfabet = alfabet
  11.  
  12.     def codeerSymbool(self, karakter: str):
  13.         if self.alfabet.__contains__(karakter):
  14.             karakter_index = self.alfabet.index(karakter)
  15.             codatie = (self.a * karakter_index + self.b) % len(self.alfabet)
  16.             return self.alfabet[codatie]
  17.         else:
  18.             return karakter
  19.            
  20.     def decodeerSymbool(self, karakter: str):
  21.         if self.alfabet.__contains__(karakter):
  22.             karakter_index = self.alfabet.index(karakter)
  23.             a_accent = 0
  24.             for i,letter in enumerate(self.alfabet):
  25.                 if (self.a * i) % len(self.alfabet) == 1:
  26.                     a_accent = i
  27.             decodatie = (a_accent * (karakter_index - self.b)) % len(self.alfabet)
  28.             return self.alfabet[decodatie]
  29.         else:
  30.             return karakter
  31.        
  32.     def codeer(self, code: str):
  33.         codatie = str()
  34.         for letter in code:
  35.             codatie += self.codeerSymbool(letter)
  36.         return codatie
  37.  
  38.     def decodeer(self, code: str):
  39.         decodatie = str()
  40.         for letter in code:
  41.             decodatie += self.decodeerSymbool(letter)
  42.         return decodatie
  43.        
  44.     def __add__(self, other):
  45.         if self.alfabet != other.alfabet:
  46.             raise AssertionError("alfabetten zijn verschillend")
  47.         tot_a = self.a * other.a
  48.         tot_b = (other.a * self.b) + other.b
  49.         return T52(tot_a, tot_b, self.alfabet)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top