def test_crypt(): crypt = Crypt("4-amino-1H-pyrimidine-2-one") ctext = crypt.encrypt("Cytosine") plain = crypt.decrypt(ctext) print plain assert plain == 'Cytosine ' ctext = crypt.encrypt("cytidinetriphosp") plain = crypt.decrypt(ctext) assert plain == 'cytidinetriphosp'
def test_crypt2(): db = {} csum = hmac.new("secret", digestmod=hashlib.sha224) csum.update("%s" % time.time()) csum.update("%f" % random.random()) txt = csum.digest() # 28 bytes long, 224 bits print len(txt) db[txt] = "foobar" txt = "%saces" % txt # another 4 bytes #print len(txt), txt crypt = Crypt("4-amino-1H-pyrimidine-2-one") ctext = crypt.encrypt(txt) onthewire = base64.b64encode(ctext) #print onthewire plain = crypt.decrypt(base64.b64decode(onthewire)) #print len(plain), plain #assert plain == txt assert plain.endswith("aces") assert db[plain[:-4]] == "foobar"
class TestCrypt(object): @pytest.fixture(autouse=True) def create_crypt(self): self.crypt = Crypt("4-amino-1H-pyrimidine-2-one") def test_encrypt_decrypt(self): ctext = self.crypt.encrypt("Cytosine") plain = self.crypt.decrypt(ctext).decode("utf-8") assert plain == 'Cytosine ' ctext = self.crypt.encrypt("cytidinetriphosp") plain = self.crypt.decrypt(ctext).decode("utf-8") assert plain == 'cytidinetriphosp' def test_crypt_with_b64(self): db = {} msg = "secret{}{}".format(time.time(), random.random()) csum = hmac.new(msg.encode("utf-8"), digestmod=hashlib.sha224) txt = csum.digest() # 28 bytes long, 224 bits db[txt] = "foobar" txt = txt + b"aces" # another 4 bytes ctext = self.crypt.encrypt(txt) onthewire = base64.b64encode(ctext) plain = self.crypt.decrypt(base64.b64decode(onthewire)) assert plain.endswith(b"aces") assert db[plain[:-4]] == "foobar"
def create_crypt(self): self.crypt = Crypt("4-amino-1H-pyrimidine-2-one")