• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  Copyright 2011 Sybren A. Stüvel <sybren@stuvel.eu>
2#
3#  Licensed under the Apache License, Version 2.0 (the "License");
4#  you may not use this file except in compliance with the License.
5#  You may obtain a copy of the License at
6#
7#      https://www.apache.org/licenses/LICENSE-2.0
8#
9#  Unless required by applicable law or agreed to in writing, software
10#  distributed under the License is distributed on an "AS IS" BASIS,
11#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12#  See the License for the specific language governing permissions and
13#  limitations under the License.
14
15"""Tests integer operations."""
16
17import unittest
18
19import rsa
20import rsa.core
21
22
23class IntegerTest(unittest.TestCase):
24    def setUp(self):
25        (self.pub, self.priv) = rsa.newkeys(64)
26
27    def test_enc_dec(self):
28        message = 42
29        print("\tMessage:   %d" % message)
30
31        encrypted = rsa.core.encrypt_int(message, self.pub.e, self.pub.n)
32        print("\tEncrypted: %d" % encrypted)
33
34        decrypted = rsa.core.decrypt_int(encrypted, self.priv.d, self.pub.n)
35        print("\tDecrypted: %d" % decrypted)
36
37        self.assertEqual(message, decrypted)
38
39    def test_sign_verify(self):
40        message = 42
41
42        signed = rsa.core.encrypt_int(message, self.priv.d, self.pub.n)
43        print("\tSigned:    %d" % signed)
44
45        verified = rsa.core.decrypt_int(signed, self.pub.e, self.pub.n)
46        print("\tVerified:  %d" % verified)
47
48        self.assertEqual(message, verified)
49