<s> """<STR_LIT>""" <EOL> from google . apputils import app <EOL> import logging <EOL> from google . apputils import basetest as googletest <EOL> import paillier <EOL> _KEY1 = '<STR_LIT>' <EOL> _PAILLIER1 = paillier . Paillier ( _KEY1 ) <EOL> class PaillierTest ( googletest . TestCase ) : <EOL> def testInitRegression ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> self . assertEquals ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , str ( _PAILLIER1 . n ) ) <EOL> self . assertEquals ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , str ( _PAILLIER1 . nsquare ) ) <EOL> self . assertEquals ( _PAILLIER1 . n + <NUM_LIT:1> , _PAILLIER1 . g ) <EOL> def testModExp ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> self . assertTrue ( paillier . _FOUND_SSL ) <EOL> a = <NUM_LIT:255> <EOL> b = <NUM_LIT> <EOL> c = <NUM_LIT> <EOL> expect = <NUM_LIT> <EOL> m1 = paillier . ModExp ( a , b , c ) <EOL> m2 = pow ( a , b , c ) <EOL> self . assertEqual ( m1 , expect ) <EOL> self . assertEqual ( m2 , expect ) <EOL> def testEncryptDecrypt ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> data = <NUM_LIT> <EOL> ciphertext = _PAILLIER1 . Encrypt ( data ) <EOL> decryption = _PAILLIER1 . Decrypt ( ciphertext ) <EOL> self . assertEquals ( data , decryption ) <EOL> def testAdd ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> plaintext1 = <NUM_LIT> <EOL> ciphertext1 = _PAILLIER1 . Encrypt ( plaintext1 ) <EOL> plaintext2 = <NUM_LIT> <EOL> ciphertext2 = _PAILLIER1 . Encrypt ( plaintext2 ) <EOL> ciphertext3 = _PAILLIER1 . Add ( ciphertext1 , ciphertext2 ) <EOL> decryption = _PAILLIER1 . Decrypt ( ciphertext3 ) <EOL> self . assertEquals ( plaintext1 + plaintext2 , decryption ) <EOL> def testAddWraparound ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> plaintext1 = _PAILLIER1 . n - <NUM_LIT:1> <EOL> ciphertext1 = _PAILLIER1 . Encrypt ( plaintext1 ) <EOL> self . assertEquals ( plaintext1 , _PAILLIER1 . Decrypt ( ciphertext1 ) ) <EOL> plaintext2 = _PAILLIER1 . n <EOL> ciphertext2 = _PAILLIER1 . Encrypt ( plaintext2 ) <EOL> self . assertEquals ( <NUM_LIT:0> , _PAILLIER1 . Decrypt ( ciphertext2 ) ) <EOL> plaintext3 = _PAILLIER1 . n + <NUM_LIT:1> <EOL> ciphertext3 = _PAILLIER1 . Encrypt ( plaintext3 ) <EOL> self . assertEquals ( <NUM_LIT:1> , _PAILLIER1 . Decrypt ( ciphertext3 ) ) <EOL> def testAffine ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> plaintext1 = <NUM_LIT> <EOL> ciphertext1 = _PAILLIER1 . Encrypt ( plaintext1 ) <EOL> a = <NUM_LIT:2> <EOL> b = <NUM_LIT> <EOL> ciphertext3 = _PAILLIER1 . Affine ( ciphertext1 , a , b ) <EOL> decryption3 = _PAILLIER1 . Decrypt ( ciphertext3 ) <EOL> self . assertEquals ( a * plaintext1 + b , decryption3 ) <EOL> ciphertext4 = _PAILLIER1 . Affine ( ciphertext1 , <NUM_LIT:0> , b ) <EOL> decryption4 = _PAILLIER1 . Decrypt ( ciphertext4 ) <EOL> self . assertEquals ( b , decryption4 ) <EOL> ciphertext5 = _PAILLIER1 . Affine ( ciphertext1 , <NUM_LIT:1> , b ) <EOL> decryption5 = _PAILLIER1 . Decrypt ( ciphertext5 ) <EOL> self . assertEquals ( plaintext1 + b , decryption5 ) <EOL> ciphertext6 = _PAILLIER1 . Affine ( ciphertext1 , <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> decryption6 = _PAILLIER1 . Decrypt ( ciphertext6 ) <EOL> self . assertEquals ( <NUM_LIT:2> * plaintext1 , decryption6 ) <EOL> ciphertext7 = _PAILLIER1 . Affine ( ciphertext1 , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> decryption7 = _PAILLIER1 . Decrypt ( ciphertext7 ) <EOL> self . assertEquals ( <NUM_LIT:0> , decryption7 ) <EOL> def testEncryptDecryptRegression ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> paillier1 = paillier . Paillier ( None , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> ciphertext = paillier1 . Encrypt ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . assertEquals ( <NUM_LIT> , ciphertext ) <EOL> decryption = paillier1 . Decrypt ( <NUM_LIT> ) <EOL> self . assertEquals ( <NUM_LIT> , decryption ) <EOL> def testGetRandomFromZNStar ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> not_relatively_prime_to_143 = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> for _ in xrange ( <NUM_LIT:20> ) : <EOL> r = _PAILLIER1 . _GetRandomFromZNStar ( <NUM_LIT:8> , <NUM_LIT> ) <EOL> self . assertFalse ( r in not_relatively_prime_to_143 ) <EOL> def testEncryptInt64DecryptInt64 ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> ciphertext = _PAILLIER1 . EncryptInt64 ( <NUM_LIT:15> ) <EOL> decryption = _PAILLIER1 . DecryptInt64 ( ciphertext ) <EOL> self . assertEquals ( <NUM_LIT:15> , decryption ) <EOL> ciphertext = _PAILLIER1 . EncryptInt64 ( - <NUM_LIT:15> ) <EOL> decryption = _PAILLIER1 . DecryptInt64 ( ciphertext ) <EOL> self . assertEquals ( - <NUM_LIT:15> , decryption ) <EOL> ciphertext = _PAILLIER1 . EncryptInt64 ( <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:1> ) <EOL> decryption = _PAILLIER1 . DecryptInt64 ( ciphertext ) <EOL> self . assertEquals ( <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:1> , decryption ) <EOL> ciphertext = _PAILLIER1 . EncryptInt64 ( - <NUM_LIT:2> ** <NUM_LIT> ) <EOL> decryption = _PAILLIER1 . DecryptInt64 ( ciphertext ) <EOL> self . assertEquals ( - <NUM_LIT:2> ** <NUM_LIT> , decryption ) <EOL> def testAddWithEncryptDecryptInt64 ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> ciphertext1 = _PAILLIER1 . EncryptInt64 ( - <NUM_LIT:15> ) <EOL> ciphertext2 = _PAILLIER1 . EncryptInt64 ( <NUM_LIT:1> ) <EOL> ciphertext3 = _PAILLIER1 . Add ( ciphertext1 , ciphertext2 ) <EOL> decryption = _PAILLIER1 . DecryptInt64 ( ciphertext3 ) <EOL> self . assertEquals ( - <NUM_LIT> , decryption ) <EOL> ciphertext1 = _PAILLIER1 . EncryptInt64 ( <NUM_LIT:15> ) <EOL> ciphertext2 = _PAILLIER1 . EncryptInt64 ( <NUM_LIT:1> ) <EOL> ciphertext3 = _PAILLIER1 . Add ( ciphertext1 , ciphertext2 ) <EOL> decryption = _PAILLIER1 . DecryptInt64 ( ciphertext3 ) <EOL> self . assertEquals ( <NUM_LIT:16> , decryption ) <EOL> ciphertext1 = _PAILLIER1 . EncryptInt64 ( - <NUM_LIT:15> ) <EOL> ciphertext2 = _PAILLIER1 . EncryptInt64 ( - <NUM_LIT:1> ) <EOL> ciphertext3 = _PAILLIER1 . Add ( ciphertext1 , ciphertext2 ) <EOL> decryption = _PAILLIER1 . DecryptInt64 ( ciphertext3 ) <EOL> self . assertEquals ( - <NUM_LIT:16> , decryption ) <EOL> def testMultipleAddWithEncryptDecryptInt64 ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> c123456789 = _PAILLIER1 . EncryptInt64 ( <NUM_LIT> L ) <EOL> c314159265359 = _PAILLIER1 . EncryptInt64 ( <NUM_LIT> L ) <EOL> c271828182846 = _PAILLIER1 . EncryptInt64 ( <NUM_LIT> L ) <EOL> c987654321neg = _PAILLIER1 . EncryptInt64 ( - <NUM_LIT> L ) <EOL> c161803398874neg = _PAILLIER1 . EncryptInt64 ( - <NUM_LIT> L ) <EOL> c1414213562373095neg = _PAILLIER1 . EncryptInt64 ( - <NUM_LIT> L ) <EOL> ciphertext = _PAILLIER1 . Add ( c123456789 , c314159265359 ) <EOL> ciphertext = _PAILLIER1 . Add ( ciphertext , c271828182846 ) <EOL> decryption = _PAILLIER1 . DecryptInt64 ( ciphertext ) <EOL> self . assertEquals ( <NUM_LIT> + <NUM_LIT> + <NUM_LIT> , decryption ) <EOL> ciphertext = _PAILLIER1 . Add ( c987654321neg , c161803398874neg ) <EOL> ciphertext = _PAILLIER1 . Add ( ciphertext , c1414213562373095neg ) <EOL> decryption = _PAILLIER1 . DecryptInt64 ( ciphertext ) <EOL> self . assertEquals ( - <NUM_LIT> + - <NUM_LIT> + - <NUM_LIT> , <EOL> decryption ) <EOL> ciphertext = _PAILLIER1 . Add ( c123456789 , c314159265359 ) <EOL> ciphertext = _PAILLIER1 . Add ( ciphertext , c271828182846 ) <EOL> ciphertext = _PAILLIER1 . Add ( ciphertext , c987654321neg ) <EOL> ciphertext = _PAILLIER1 . Add ( ciphertext , c161803398874neg ) <EOL> ciphertext_3pos_2neg = ciphertext <EOL> decryption = _PAILLIER1 . DecryptInt64 ( ciphertext ) <EOL> sum_3pos_2neg = ( <NUM_LIT> + <NUM_LIT> + <NUM_LIT> + - <NUM_LIT> + <EOL> - <NUM_LIT> ) <EOL> self . assertEquals ( sum_3pos_2neg , decryption ) <EOL> ciphertext = _PAILLIER1 . Add ( c123456789 , c314159265359 ) <EOL> ciphertext = _PAILLIER1 . Add ( ciphertext , c271828182846 ) <EOL> ciphertext = _PAILLIER1 . Add ( ciphertext , c987654321neg ) <EOL> ciphertext = _PAILLIER1 . Add ( ciphertext , c161803398874neg ) <EOL> ciphertext = _PAILLIER1 . Add ( ciphertext , c1414213562373095neg ) <EOL> ciphertext_3pos_3neg = ciphertext <EOL> decryption = _PAILLIER1 . DecryptInt64 ( ciphertext ) <EOL> sum_3pos_3neg = ( <NUM_LIT> + <NUM_LIT> + <NUM_LIT> + - <NUM_LIT> + <EOL> - <NUM_LIT> + - <NUM_LIT> ) <EOL> self . assertEquals ( sum_3pos_3neg , decryption ) <EOL> ciphertext = _PAILLIER1 . EncryptInt64 ( <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:1> - sum_3pos_2neg ) <EOL> ciphertext = _PAILLIER1 . Add ( ciphertext_3pos_2neg , ciphertext ) <EOL> decryption = _PAILLIER1 . DecryptInt64 ( ciphertext ) <EOL> self . assertEquals ( <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:1> , decryption ) <EOL> ciphertext = _PAILLIER1 . EncryptInt64 ( - <NUM_LIT:2> ** <NUM_LIT> + <NUM_LIT:1> - sum_3pos_3neg ) <EOL> ciphertext = _PAILLIER1 . Add ( ciphertext_3pos_3neg , ciphertext ) <EOL> decryption = _PAILLIER1 . DecryptInt64 ( ciphertext ) <EOL> self . assertEquals ( - <NUM_LIT:2> ** <NUM_LIT> + <NUM_LIT:1> , decryption ) <EOL> ciphertext = _PAILLIER1 . EncryptInt64 ( - <NUM_LIT:2> ** <NUM_LIT> - sum_3pos_3neg ) <EOL> ciphertext = _PAILLIER1 . Add ( ciphertext_3pos_3neg , ciphertext ) <EOL> decryption = _PAILLIER1 . DecryptInt64 ( ciphertext ) <EOL> self . assertEquals ( - <NUM_LIT:2> ** <NUM_LIT> , decryption ) <EOL> def testEncryptInt64Fail ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> try : <EOL> _PAILLIER1 . EncryptInt64 ( <NUM_LIT:2> ** <NUM_LIT> ) <EOL> self . fail ( ) <EOL> except ValueError : <EOL> pass <EOL> try : <EOL> _PAILLIER1 . EncryptInt64 ( <NUM_LIT:2> ** <NUM_LIT> ) <EOL> self . fail ( ) <EOL> except ValueError : <EOL> pass <EOL> try : <EOL> _PAILLIER1 . EncryptInt64 ( - <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:1> ) <EOL> self . fail ( ) <EOL> except ValueError : <EOL> pass <EOL> try : <EOL> _PAILLIER1 . EncryptInt64 ( - <NUM_LIT:2> ** <NUM_LIT> ) <EOL> self . fail ( ) <EOL> except ValueError : <EOL> pass <EOL> ciphertext1 = _PAILLIER1 . EncryptInt64 ( <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:1> ) <EOL> ciphertext2 = _PAILLIER1 . EncryptInt64 ( <NUM_LIT:1> ) <EOL> ciphertext3 = _PAILLIER1 . Add ( ciphertext1 , ciphertext2 ) <EOL> try : <EOL> _PAILLIER1 . DecryptInt64 ( ciphertext3 ) <EOL> self . fail ( ) <EOL> except OverflowError : <EOL> pass <EOL> ciphertext1 = _PAILLIER1 . EncryptInt64 ( - <NUM_LIT:2> ** <NUM_LIT> ) <EOL> ciphertext2 = _PAILLIER1 . EncryptInt64 ( - <NUM_LIT:1> ) <EOL> ciphertext3 = _PAILLIER1 . Add ( ciphertext1 , ciphertext2 ) <EOL> try : <EOL> _PAILLIER1 . DecryptInt64 ( ciphertext3 ) <EOL> self . fail ( ) <EOL> except OverflowError : <EOL> pass <EOL> def testFloatBasicMethods ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> self . assertTrue ( paillier . IsNan ( float ( '<STR_LIT>' ) ) ) <EOL> for f in ( <NUM_LIT> , <NUM_LIT> ) : <EOL> self . assertTrue ( paillier . IsInfPlus ( f ) ) <EOL> self . assertFalse ( paillier . IsInfMinus ( f ) ) <EOL> self . assertFalse ( paillier . IsNan ( f ) ) <EOL> for f in ( - <NUM_LIT> , - <NUM_LIT> ) : <EOL> self . assertTrue ( paillier . IsInfMinus ( f ) ) <EOL> self . assertFalse ( paillier . IsInfPlus ( f ) ) <EOL> self . assertFalse ( paillier . IsNan ( f ) ) <EOL> def testEncryptDecryptFloatInfAndNan ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> nan_value = float ( '<STR_LIT>' ) <EOL> c_nan = _PAILLIER1 . EncryptFloat ( nan_value ) <EOL> self . assertTrue ( paillier . IsNan ( _PAILLIER1 . DecryptFloat ( c_nan ) ) ) <EOL> c_2nan = _PAILLIER1 . Add ( c_nan , c_nan ) <EOL> self . assertTrue ( paillier . IsNan ( _PAILLIER1 . DecryptFloat ( c_2nan ) ) ) <EOL> c_plus_inf = _PAILLIER1 . EncryptFloat ( <NUM_LIT> ) <EOL> self . assertTrue ( paillier . IsInfPlus ( _PAILLIER1 . DecryptFloat ( c_plus_inf ) ) ) <EOL> c_2plus_inf = _PAILLIER1 . Add ( c_plus_inf , c_plus_inf ) <EOL> self . assertTrue ( paillier . IsInfPlus ( _PAILLIER1 . DecryptFloat ( c_2plus_inf ) ) ) <EOL> c_minus_inf = _PAILLIER1 . EncryptFloat ( - <NUM_LIT> ) <EOL> self . assertTrue ( paillier . IsInfMinus ( _PAILLIER1 . DecryptFloat ( c_minus_inf ) ) ) <EOL> c_2minus_inf = _PAILLIER1 . Add ( c_minus_inf , c_minus_inf ) <EOL> self . assertTrue ( paillier . IsInfMinus ( _PAILLIER1 . DecryptFloat ( c_2minus_inf ) ) ) <EOL> c_sum_plus_minus_inf = _PAILLIER1 . Add ( c_plus_inf , c_minus_inf ) <EOL> self . assertTrue ( <EOL> paillier . IsNan ( _PAILLIER1 . DecryptFloat ( c_sum_plus_minus_inf ) ) ) <EOL> c_sum_inf_nan = _PAILLIER1 . Add ( c_plus_inf , c_nan ) <EOL> self . assertTrue ( paillier . IsNan ( _PAILLIER1 . DecryptFloat ( c_sum_inf_nan ) ) ) <EOL> c_1_0 = _PAILLIER1 . EncryptFloat ( <NUM_LIT:1.0> ) <EOL> c_1_0neg = _PAILLIER1 . EncryptFloat ( - <NUM_LIT:1.0> ) <EOL> c_sum_fin_nan = _PAILLIER1 . Add ( c_1_0 , c_nan ) <EOL> self . assertTrue ( paillier . IsNan ( _PAILLIER1 . DecryptFloat ( c_sum_fin_nan ) ) ) <EOL> c_sum_fin_nan = _PAILLIER1 . Add ( c_1_0neg , c_nan ) <EOL> self . assertTrue ( paillier . IsNan ( _PAILLIER1 . DecryptFloat ( c_sum_fin_nan ) ) ) <EOL> c_sum_plus_inf = _PAILLIER1 . Add ( c_1_0 , c_plus_inf ) <EOL> self . assertTrue ( <EOL> paillier . IsInfPlus ( _PAILLIER1 . DecryptFloat ( c_sum_plus_inf ) ) ) <EOL> c_sum_plus_inf = _PAILLIER1 . Add ( c_1_0neg , c_plus_inf ) <EOL> self . assertTrue ( <EOL> paillier . IsInfPlus ( _PAILLIER1 . DecryptFloat ( c_sum_plus_inf ) ) ) <EOL> c_sum_minus_inf = _PAILLIER1 . Add ( c_1_0 , c_minus_inf ) <EOL> self . assertTrue ( <EOL> paillier . IsInfMinus ( _PAILLIER1 . DecryptFloat ( c_sum_minus_inf ) ) ) <EOL> c_sum_minus_inf = _PAILLIER1 . Add ( c_1_0neg , c_minus_inf ) <EOL> self . assertTrue ( <EOL> paillier . IsInfMinus ( _PAILLIER1 . DecryptFloat ( c_sum_minus_inf ) ) ) <EOL> def testEncryptDecryptFloatSmallNormalNumbers ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> c_1_0 = _PAILLIER1 . EncryptFloat ( <NUM_LIT:1.0> ) <EOL> self . assertEquals ( <NUM_LIT:1.0> , _PAILLIER1 . DecryptFloat ( c_1_0 ) ) <EOL> c_15_1234 = _PAILLIER1 . EncryptFloat ( <NUM_LIT> ) <EOL> self . assertEquals ( <NUM_LIT> , _PAILLIER1 . DecryptFloat ( c_15_1234 ) ) <EOL> c_1_0neg = _PAILLIER1 . EncryptFloat ( - <NUM_LIT:1.0> ) <EOL> self . assertEquals ( - <NUM_LIT:1.0> , _PAILLIER1 . DecryptFloat ( c_1_0neg ) ) <EOL> c_15_1234neg = _PAILLIER1 . EncryptFloat ( - <NUM_LIT> ) <EOL> self . assertEquals ( - <NUM_LIT> , _PAILLIER1 . DecryptFloat ( c_15_1234neg ) ) <EOL> data = <NUM_LIT> <EOL> c_smallest_gt_1 = _PAILLIER1 . EncryptFloat ( data ) <EOL> self . assertEquals ( data , <EOL> _PAILLIER1 . DecryptFloat ( c_smallest_gt_1 ) ) <EOL> self . assertNotEquals ( <NUM_LIT:1.0> , _PAILLIER1 . DecryptFloat ( c_smallest_gt_1 ) ) <EOL> data = <NUM_LIT> <EOL> self . assertEquals ( <EOL> <NUM_LIT:1.0> , _PAILLIER1 . DecryptFloat ( _PAILLIER1 . EncryptFloat ( data ) ) ) <EOL> data = - <NUM_LIT> <EOL> c_smallest_lt_1neg = _PAILLIER1 . EncryptFloat ( data ) <EOL> self . assertEquals ( data , <EOL> _PAILLIER1 . DecryptFloat ( c_smallest_lt_1neg ) ) <EOL> self . assertNotEquals ( - <NUM_LIT:1.0> , _PAILLIER1 . DecryptFloat ( c_smallest_lt_1neg ) ) <EOL> self . assertEquals ( - <NUM_LIT:1.0> , <EOL> _PAILLIER1 . DecryptFloat ( _PAILLIER1 . EncryptFloat ( <EOL> - <NUM_LIT> ) ) ) <EOL> c_onethird = _PAILLIER1 . EncryptFloat ( <NUM_LIT:1.0> / <NUM_LIT> ) <EOL> self . assertEquals ( <NUM_LIT:1.0> / <NUM_LIT> , _PAILLIER1 . DecryptFloat ( c_onethird ) ) <EOL> c_onethird = _PAILLIER1 . EncryptFloat ( - <NUM_LIT:1.0> / <NUM_LIT> ) <EOL> self . assertEquals ( - <NUM_LIT:1.0> / <NUM_LIT> , _PAILLIER1 . DecryptFloat ( c_onethird ) ) <EOL> smallest_normal = <NUM_LIT:2> ** - <NUM_LIT> <EOL> self . assertEquals ( smallest_normal , _PAILLIER1 . DecryptFloat ( <EOL> _PAILLIER1 . EncryptFloat ( smallest_normal ) ) ) <EOL> near_smallest_normal = <NUM_LIT> * <NUM_LIT:2> ** - <NUM_LIT> <EOL> self . assertEquals ( near_smallest_normal , _PAILLIER1 . DecryptFloat ( <EOL> _PAILLIER1 . EncryptFloat ( near_smallest_normal ) ) ) <EOL> smallest_normal = - <NUM_LIT:2> ** - <NUM_LIT> <EOL> self . assertEquals ( smallest_normal , _PAILLIER1 . DecryptFloat ( <EOL> _PAILLIER1 . EncryptFloat ( smallest_normal ) ) ) <EOL> near_smallest_normal = - <NUM_LIT> * <NUM_LIT:2> ** - <NUM_LIT> <EOL> self . assertEquals ( near_smallest_normal , _PAILLIER1 . DecryptFloat ( <EOL> _PAILLIER1 . EncryptFloat ( near_smallest_normal ) ) ) <EOL> def testEncryptDecryptFloatSubNormalNumbers ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> smallest_subnormal = <NUM_LIT:2> ** - <NUM_LIT> <EOL> c_smallest_subnormal = _PAILLIER1 . EncryptFloat ( smallest_subnormal ) <EOL> self . assertEquals ( smallest_subnormal , <EOL> _PAILLIER1 . DecryptFloat ( c_smallest_subnormal ) ) <EOL> self . assertEquals ( <NUM_LIT:0.0> , _PAILLIER1 . DecryptFloat ( _PAILLIER1 . EncryptFloat ( <EOL> <NUM_LIT:2> ** - <NUM_LIT> ) ) ) <EOL> smallest_subnormal = - <NUM_LIT:2> ** - <NUM_LIT> <EOL> c_smallest_subnormal = _PAILLIER1 . EncryptFloat ( smallest_subnormal ) <EOL> self . assertEquals ( smallest_subnormal , <EOL> _PAILLIER1 . DecryptFloat ( c_smallest_subnormal ) ) <EOL> self . assertEquals ( <NUM_LIT:0.0> , _PAILLIER1 . DecryptFloat ( _PAILLIER1 . EncryptFloat ( <EOL> - <NUM_LIT:2> ** - <NUM_LIT> ) ) ) <EOL> def testEncryptDecryptFloatLargeFiniteNumbers ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> large1 = <NUM_LIT> * <NUM_LIT:2> ** <NUM_LIT> <EOL> large2 = <NUM_LIT> * <NUM_LIT:2> ** <NUM_LIT:100> <EOL> c_large1 = _PAILLIER1 . EncryptFloat ( large1 ) <EOL> self . assertEquals ( large1 , _PAILLIER1 . DecryptFloat ( c_large1 ) ) <EOL> c_large2 = _PAILLIER1 . EncryptFloat ( large2 ) <EOL> self . assertEquals ( large2 , _PAILLIER1 . DecryptFloat ( c_large2 ) ) <EOL> c_mantissa17digits = _PAILLIER1 . EncryptFloat ( <EOL> <NUM_LIT> ) <EOL> self . assertEquals ( <NUM_LIT> , <EOL> _PAILLIER1 . DecryptFloat ( c_mantissa17digits ) ) <EOL> c_mantissa18digits = _PAILLIER1 . EncryptFloat ( <EOL> <NUM_LIT> ) <EOL> decrypted = _PAILLIER1 . DecryptFloat ( c_mantissa18digits ) <EOL> self . assertNotEquals ( <NUM_LIT> , decrypted ) <EOL> self . assertTrue ( abs ( decrypted - <NUM_LIT> ) <= <NUM_LIT> ) <EOL> largest_normal = <NUM_LIT> * <NUM_LIT:2> ** <NUM_LIT> <EOL> c_largest_normal = _PAILLIER1 . EncryptFloat ( largest_normal ) <EOL> self . assertEquals ( largest_normal , _PAILLIER1 . DecryptFloat ( c_largest_normal ) ) <EOL> try : <EOL> beyond_largest_normal = <NUM_LIT:1.0> * <NUM_LIT:2> ** <NUM_LIT> <EOL> _PAILLIER1 . EncryptFloat ( beyond_largest_normal ) <EOL> self . fail ( ) <EOL> except ValueError : <EOL> pass <EOL> c_mantissa17digits_neg = _PAILLIER1 . EncryptFloat ( <EOL> - <NUM_LIT> ) <EOL> self . assertEquals ( - <NUM_LIT> , <EOL> _PAILLIER1 . DecryptFloat ( c_mantissa17digits_neg ) ) <EOL> c_mantissa18digits_neg = _PAILLIER1 . EncryptFloat ( <EOL> - <NUM_LIT> ) <EOL> decrypted = _PAILLIER1 . DecryptFloat ( c_mantissa18digits_neg ) <EOL> self . assertNotEquals ( - <NUM_LIT> , decrypted ) <EOL> self . assertTrue ( abs ( decrypted - - <NUM_LIT> ) <= <NUM_LIT> ) <EOL> largest_normal = - <NUM_LIT> * <NUM_LIT:2> ** <NUM_LIT> <EOL> c_largest_normal = _PAILLIER1 . EncryptFloat ( largest_normal ) <EOL> self . assertEquals ( largest_normal , _PAILLIER1 . DecryptFloat ( c_largest_normal ) ) <EOL> try : <EOL> beyond_largest_normal = - <NUM_LIT:1.0> * <NUM_LIT:2> ** <NUM_LIT> <EOL> _PAILLIER1 . EncryptFloat ( beyond_largest_normal ) <EOL> self . fail ( ) <EOL> except ValueError : <EOL> pass <EOL> def testEncryptDecryptFloatAddFiniteNumbers ( self ) : <EOL> logging . debug ( '<STR_LIT>' ) <EOL> c_1_0 = _PAILLIER1 . EncryptFloat ( <NUM_LIT:1.0> ) <EOL> c_2_0 = _PAILLIER1 . EncryptFloat ( <NUM_LIT> ) <EOL> c_3_0 = _PAILLIER1 . Add ( c_2_0 , c_1_0 ) <EOL> c_5_0 = _PAILLIER1 . Add ( c_3_0 , c_2_0 ) <EOL> self . assertEquals ( <NUM_LIT> , _PAILLIER1 . DecryptFloat ( c_3_0 ) ) <EOL> self . assertEquals ( <NUM_LIT> , _PAILLIER1 . DecryptFloat ( c_5_0 ) ) <EOL> c_2_0neg = _PAILLIER1 . EncryptFloat ( - <NUM_LIT> ) <EOL> c_4_0neg = _PAILLIER1 . EncryptFloat ( - <NUM_LIT> ) <EOL> c_6_0neg = _PAILLIER1 . Add ( c_2_0neg , c_4_0neg ) <EOL> self . assertEquals ( - <NUM_LIT> , _PAILLIER1 . DecryptFloat ( c_6_0neg ) ) <EOL> c_1_0neg = _PAILLIER1 . Add ( c_5_0 , c_6_0neg ) <EOL> self . assertEquals ( - <NUM_LIT:1.0> , _PAILLIER1 . DecryptFloat ( c_1_0neg ) ) <EOL> large1 = <NUM_LIT> * <NUM_LIT:2> ** <NUM_LIT> <EOL> c_large1 = _PAILLIER1 . EncryptFloat ( large1 ) <EOL> c_large2neg = _PAILLIER1 . EncryptFloat ( - <NUM_LIT> * <NUM_LIT:2> ** <NUM_LIT> ) <EOL> decrypted = _PAILLIER1 . DecryptFloat ( _PAILLIER1 . Add ( c_large1 , c_large2neg ) ) <EOL> self . assertTrue ( decrypted > <NUM_LIT> * <NUM_LIT:2> ** <NUM_LIT> ) <EOL> self . assertTrue ( decrypted < <NUM_LIT> * <NUM_LIT:2> ** <NUM_LIT> ) <EOL> c_small1 = _PAILLIER1 . EncryptFloat ( <NUM_LIT> * <NUM_LIT:2> ** - <NUM_LIT> ) <EOL> decrypted = _PAILLIER1 . DecryptFloat ( _PAILLIER1 . Add ( c_large1 , c_small1 ) ) <EOL> self . assertEquals ( large1 , decrypted ) <EOL> smallest_subnormal = <NUM_LIT:2> ** - <NUM_LIT> <EOL> c_smallest_subnormal = _PAILLIER1 . EncryptFloat ( smallest_subnormal ) <EOL> c_2smallest_subnormal = _PAILLIER1 . Add ( c_smallest_subnormal , <EOL> c_smallest_subnormal ) <EOL> self . assertEquals ( <NUM_LIT:2> ** - <NUM_LIT> , _PAILLIER1 . DecryptFloat ( c_2smallest_subnormal ) ) <EOL> c_smallest_subnormal_neg = _PAILLIER1 . EncryptFloat ( - <NUM_LIT:2> ** - <NUM_LIT> ) <EOL> self . assertEquals ( smallest_subnormal , _PAILLIER1 . DecryptFloat ( <EOL> _PAILLIER1 . Add ( c_2smallest_subnormal , c_smallest_subnormal_neg ) ) ) <EOL> def testEncryptDecryptMultipleInt64s ( self ) : <EOL> plain_numbers = [ <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:15> , - <NUM_LIT:15> , <NUM_LIT:0> ] <EOL> ciphertext = _PAILLIER1 . EncryptMultipleInt64s ( plain_numbers ) <EOL> decryption = _PAILLIER1 . DecryptMultipleInt64s ( ciphertext ) <EOL> self . assertEquals ( plain_numbers , decryption ) <EOL> plain_numbers = [ - <NUM_LIT:9> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:1> , - <NUM_LIT:2> ** <NUM_LIT> , <NUM_LIT:100> ] <EOL> ciphertext = _PAILLIER1 . EncryptMultipleInt64s ( plain_numbers ) <EOL> decryption = _PAILLIER1 . DecryptMultipleInt64s ( ciphertext ) <EOL> self . assertEquals ( plain_numbers , decryption ) <EOL> plain_numbers = [ <NUM_LIT> L , <NUM_LIT> L , <NUM_LIT> L , - <NUM_LIT> L , <EOL> <NUM_LIT> L , <NUM_LIT> L , <NUM_LIT:0> L ] <EOL> ciphertext = _PAILLIER1 . EncryptMultipleInt64s ( plain_numbers ) <EOL> decryption = _PAILLIER1 . DecryptMultipleInt64s ( ciphertext ) <EOL> self . assertEquals ( plain_numbers , decryption ) <EOL> def testAddMultipleInt64s ( self ) : <EOL> ciphertext1 = _PAILLIER1 . EncryptMultipleInt64s ( [ <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT:15> , <NUM_LIT:15> , - <NUM_LIT:15> ] ) <EOL> ciphertext2 = _PAILLIER1 . EncryptMultipleInt64s ( [ <NUM_LIT:50> , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , - <NUM_LIT:1> ] ) <EOL> ciphertext3 = _PAILLIER1 . Add ( ciphertext1 , ciphertext2 ) <EOL> decryption = _PAILLIER1 . DecryptMultipleInt64s ( ciphertext3 ) <EOL> self . assertEquals ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:0> , - <NUM_LIT> , <NUM_LIT:16> , - <NUM_LIT:16> ] , decryption ) <EOL> ciphers_sum = _PAILLIER1 . EncryptMultipleInt64s ( [ <NUM_LIT:0> ] ) <EOL> for _ in xrange ( <NUM_LIT:100> ) : <EOL> ciphers_sum = _PAILLIER1 . Add ( ciphers_sum , ciphertext1 ) <EOL> decryption = _PAILLIER1 . DecryptMultipleInt64s ( ciphers_sum ) <EOL> self . assertEquals ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ] , decryption ) <EOL> ciphertext1 = _PAILLIER1 . EncryptMultipleInt64s ( <EOL> [ <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> L , - <NUM_LIT:2> ** <NUM_LIT> , <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:1> , - <NUM_LIT:2> ** <NUM_LIT> + <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> ciphertext2 = _PAILLIER1 . EncryptMultipleInt64s ( <EOL> [ <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> L , - <NUM_LIT:15> , - <NUM_LIT:15> , - <NUM_LIT:15> , <NUM_LIT:0> ] ) <EOL> ciphertext3 = _PAILLIER1 . EncryptMultipleInt64s ( <EOL> [ <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:0> ] ) <EOL> ciphertext4 = _PAILLIER1 . EncryptMultipleInt64s ( <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> ciphertext5 = _PAILLIER1 . EncryptMultipleInt64s ( <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> ciphers_sum = _PAILLIER1 . Add ( ciphertext1 , ciphertext2 ) <EOL> ciphers_sum = _PAILLIER1 . Add ( ciphers_sum , ciphertext3 ) <EOL> ciphers_sum = _PAILLIER1 . Add ( ciphers_sum , ciphertext4 ) <EOL> ciphers_sum = _PAILLIER1 . Add ( ciphers_sum , ciphertext5 ) <EOL> decryption = _PAILLIER1 . DecryptMultipleInt64s ( ciphers_sum ) <EOL> positive_sum = <NUM_LIT> + <NUM_LIT> + <NUM_LIT> <EOL> negative_sum = - <NUM_LIT> + - <NUM_LIT> + - <NUM_LIT> <EOL> total = <NUM_LIT> + <NUM_LIT> + <NUM_LIT> - <NUM_LIT> - <NUM_LIT> <EOL> self . assertEquals ( [ positive_sum , negative_sum , total , - <NUM_LIT:2> ** <NUM_LIT> , <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:1> , <EOL> - <NUM_LIT:2> ** <NUM_LIT> + <NUM_LIT:1> , <NUM_LIT:0> ] , decryption ) <EOL> def testEncryptDecryptMultipleInt64sFail ( self ) : <EOL> try : <EOL> _PAILLIER1 . EncryptMultipleInt64s ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> self . fail ( ) <EOL> except ValueError : <EOL> pass <EOL> try : <EOL> _PAILLIER1 . EncryptMultipleInt64s ( [ <NUM_LIT:2> ** <NUM_LIT> , <NUM_LIT:0> ] ) <EOL> self . fail ( ) <EOL> except ValueError : <EOL> pass <EOL> try : <EOL> _PAILLIER1 . EncryptMultipleInt64s ( [ - <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> self . fail ( ) <EOL> except ValueError : <EOL> pass <EOL> ciphertext1 = _PAILLIER1 . EncryptMultipleInt64s ( [ <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> ciphertext2 = _PAILLIER1 . EncryptMultipleInt64s ( [ <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> ciphertext3 = _PAILLIER1 . Add ( ciphertext1 , ciphertext2 ) <EOL> try : <EOL> _PAILLIER1 . DecryptMultipleInt64s ( ciphertext3 ) <EOL> self . fail ( ) <EOL> except OverflowError : <EOL> pass <EOL> ciphertext1 = _PAILLIER1 . EncryptMultipleInt64s ( [ - <NUM_LIT:2> ** <NUM_LIT> , <NUM_LIT:0> ] ) <EOL> ciphertext2 = _PAILLIER1 . EncryptMultipleInt64s ( [ - <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> ciphertext3 = _PAILLIER1 . Add ( ciphertext1 , ciphertext2 ) <EOL> try : <EOL> _PAILLIER1 . DecryptMultipleInt64s ( ciphertext3 ) <EOL> self . fail ( ) <EOL> except OverflowError : <EOL> pass <EOL> def testTestSslRegression ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertTrue ( paillier . _FOUND_SSL ) <EOL> paillier . TestSslRegression ( ) <EOL> def main ( _ ) : <EOL> googletest . main ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app . run ( ) </s>
