crip-tografia de chave pública RSA, com tamanho de chave de 1024 bits, da biblioteca PyCrypto, obteve-se a média de tempo de 0,032 segundo para transferir uma chave criptográfica simétrica, com a melhor aproximação ao tempo de sincronização sendo de duas TPM configuradas com K=3,N=4 eL=3, com média de tempo de 0,048.
Cabe ressaltar que trata-se de uma implementação do algoritmo RSA já otimizada e imple-mentada em linguagem C, que tende a ser até 700 vezes mais rápidas que Python em algumas simulações (SCYPY.ORG, 2011). Portanto uma melhor comparação poderia ser feita caso o algoritmo de sincronização de redes neurais fosse desenvolvido também em linguagem C.
linguagem C, reconhecidamente mais performática.
O algoritmo de criptografia neural implementado é uma das alternativas ao problema de troca de chaves. Tem como característica precisar, em geral, de um número mais baixo de cálculos que alternativas de chave pública (KANTER; KINZEL; KANTER, 2002). Adicio-nalmente, a criptografia neural não possui algumas das desvantagens encontradas em outras técnicas, como a troca de chave com antecedência, que é logísticamente inviável, e que o uso de um terceiro confiável, que depende exclusivamente de uma máquina mestre com acesso a todas as informações.
Como trabalho futuro, sugere-se a implementação do protocolo em linguagem C para a realização de comparação entre a performance e segurança da criptografia neural em relação à criptografia de chave pública juntamente com a implementação das melhorias já propostas ao protocolo, sendo o uso de queries e a transmissão de informações errôneas com predição.
Também se sugere a implementação do protocolo em microcontroladores e dispositivos com-putacionais mais limitados, como por exemplo, telefones celulares.
Referências Bibliográficas
AHN, L. V. et al. Captcha: using hard ai problems for security. In: Proceedings of the 22nd international conference on Theory and applications of cryptographic techniques. Berlin, Heidelberg: Springer-Verlag, 2003. (EUROCRYPT’03), p. 294–311. ISBN 3-540-14039-5.
Disponível em:<http://portal.acm.org/citation.cfm?id=1766171.1766196>.
ALLAM, A. M.; ABBAS, H. M. On the improvement of neural cryptography using erroneous transmitted information with error prediction.Trans. Neur. Netw., IEEE Press, Piscataway, NJ, USA, v. 21, p. 1915–1924, December 2010. ISSN 1045-9227. Disponível em:
<http://dx.doi.org/10.1109/TNN.2010.2079948>.
BELLMAN, R. E. An introduction to artificial intelligence: Can computers think? Boyd &
Fraser Publishing Company, 1978.
BISHOP, M.Computer security: art and science. [S.l.]: Addison-Wesley, 2003. ISBN 9780201440997.
BRAGA, A.; CARVALHO, A.; LUDERMIR, T.Redes Neurais Artificiais: Teoria e Aplicações.
2. ed. [S.l.]: LTC, 2007. ISBN 9788521615644.
BURNETT, S.; PAINE, S.The RSA Security’s Official Guide to Cryptography. Berkeley, CA, USA: Osborne/McGraw-Hill, 2001. ISBN 0072194049.
ENGELBRECHT, A.Computational Intelligence: An Introduction. New York, NY, USA:
Halsted Press, 2002. ISBN 0470848707.
FILHO, J. F. Implementação e análise de desempenho dos protocolos de criptografia neural e diffie-hellman em sistemas rfid utilizando uma plataforma embarcada.Universidade Federal do Rio Grande do Norte, p. 61, 2009.
FRANK, J.; MDA-C, N. U. Artificial intelligence and intrusion detection: Current and future directions. In:In Proceedings of the 17th National Computer Security Conference. [S.l.: s.n.], 1994.
GOLDREICH, O. Foundations of Cryptography: Basic Tools. New York, NY, USA:
Cambridge University Press, 2000. ISBN 0521791723.
HAYKIN, S.Neural networks: a comprehensive foundation. [S.l.]: Prentice Hall, 1999. ISBN 9780132733502.
KANTER, I.; KINZEL, W.; KANTER, E. Secure exchange of information by synchronization of neural networks.Europhysics Letters, IOP Publishing, v. 57, n. 1, p. 11, 2002. Disponível
em:<http://arxiv.org/abs/cond-mat/0202112>.
KINZEL, W.; KANTER, I. Neural cryptography. In: in Proc. of the 9th International Conference on Neural Information Processing. [S.l.: s.n.], 2002. p. 18–22.
KURZWEIL, R. The age of intelligent machines. MIT Press, 1990.
MENEZES, A. J.; VANSTONE, S. A.; OORSCHOT, P. C. V. Handbook of Applied Cryptography. 1st. ed. Boca Raton, FL, USA: CRC Press, Inc., 1996. ISBN 0849385237.
NILSSON, N. J. Artificial intelligence: A new synthesis. Morgan Kaufmann, 1998.
PFLEEGER, C. P.; PFLEEGER, S. L.Security in Computing (4th Edition). Upper Saddle River, NJ, USA: Prentice Hall PTR, 2006. ISBN 0132390779.
POOLE, D.; MACKWORTH, A. K.; GOEBEL, R.Computational Intelligence: A logical approach. [S.l.]: Oxford University Press, 1998.
PRABAKARAN, N.; P., V. A new security on neural cryptography with queries.Int. J. of Advanced Networking and Applications, p. 437–444, 2010.
ROWLEY, H. A.Neural network-based face detection. Tese (Doutorado), Pittsburgh, PA, USA, 1999. AAI9950035.
RUSSELL, S.; NORVIG, P.Artificial intelligence: a modern approach. [S.l.]: Prentice Hall, 2010. (Prentice Hall series in artificial intelligence). ISBN 9780136042594.
RUTTOR, A. Neural synchronization and cryptography.arXiv, p. 120, 2007. Disponível em:
<http://arxiv.org/abs/0711.2411>.
RUTTOR, A.; KINZEL, W.; KANTER, I. Neural Cryptography with Queries. nov. 2004.
Disponível em:<http://arxiv.org/abs/cond-mat/0411374>.
Ruttor, A.; Kinzel, W.; Kanter, I. Neural cryptography with queries.Journal of Statistical Mechanics: Theory and Experiment, v. 1, p. 9–+, jan. 2005.
RUTTOR, A. et al. Genetic attack on neural cryptography.Physical Review E - Statistical, Nonlinear and Soft Matter Physics, APS, v. 73, n. 3 Pt 2, p. 036121, 2006. Disponível em:
<http://arxiv.org/abs/cond-mat/0512022>.
SCYPY.ORG. Performance Python. 6 2011. Disponível em:
<http://www.scipy.org/PerformancePython>.
SHACHAM, L. N. et al.Cooperating Attackers in Neural Cryptography. [S.l.], Dec 2003.
TERADA, R.Segurança de Dados: Criptografia em Rede de Computador. 2nd. ed. [S.l.]:
Edgard Blucher, 2008. ISBN 9788521204398.
WINSTON, P. H.Artificial Intelligence. 3. ed. [S.l.]: Addison-Wesley, 1992.
APÊNDICE A -- Implementação da Tree Parity Machine
Código A.1: Implementação de uma Tree Parity Machine
1 # −∗− c o d i n g : u t f−8 −∗−
2 i m p o r t random
3 i m p o r t math
4 from l r u l e i m p o r t ∗
5 from u n i t i m p o r t U n i t
6 7
8 c l a s s T r e e P a r i t y M a c h i n e ( o b j e c t ) :
9
10 d e f _ _ i n i t _ _ ( s e l f , K= 3 , N= 4 , L = 3 , l r u l e = H e b b i a n ) :
11 s e l f . u n i t s = [ ]
12 s e l f . K = K
13 s e l f . N = N
14 s e l f . y = None
15 f o r u n i t i n r a n g e (K) :
16 s e l f . u n i t s . a p p e n d ( U n i t ( N , L , l r u l e ) )
17
18 d e f _ _ c a l l _ _ ( s e l f , x ) :
19 s e l f . y = 1
20 s e l f . x = x
21 x = s e l f . _ c h u n k s ( x , s e l f . N)
22 f o r u n i t , x i i n z i p ( s e l f . u n i t s , x ) :
23 s e l f . y = s e l f . y ∗ u n i t ( x i )
24 r e t u r n s e l f . y
25
26 d e f _ c h u n k s ( s e l f , l , c h u n k _ s i z e ) :
27 o f f s e t = 0
28 c h u n k s = [ ]
29 f o r i i n r a n g e ( l e n ( l ) / c h u n k _ s i z e ) :
30 c h u n k = [ ]
31 f o r j i n r a n g e ( c h u n k _ s i z e ) :
32 c h u n k . a p p e n d ( l [ o f f s e t + j ] )
33 o f f s e t = o f f s e t + j + 1
34 c h u n k s . a p p e n d ( c h u n k )
35 r e t u r n c h u n k s
36
37 d e f a c t i v a t i o n ( s e l f , y ) :
38 r e t u r n ( s e l f . y == y )
39
40 d e f t r a i n ( s e l f , x=None ) :
41 x = x or s e l f . x
42 x = s e l f . _ c h u n k s ( x , s e l f . N)
43 f o r u n i t , x i i n z i p ( s e l f . u n i t s , x ) :
44 u n i t . t r a i n ( x i , s e l f . y )
45
46 d e f w e i g h t s ( s e l f ) :
47 w = [ ]
48 f o r u n i t i n s e l f . u n i t s :
49 f o r wi i n u n i t . w :
50 w . a p p e n d ( wi )
51 r e t u r n w
52
53 d e f o u t p u t s ( s e l f ) :
54 w = [ ]
55 f o r u n i t i n s e l f . u n i t s :
56 w . a p p e n d ( u n i t . o )
57 r e t u r n w
58
59 d e f g e n e r a t e _ i n p u t s ( s e l f ) :
60 s e l f . x = [ [−1 , 1 ] [ random . r a n d i n t ( 0 , 1 ) ] f o r w h a t e v e r i n r a n g e ( s e l f . K
∗ s e l f . N) ]
61 r e t u r n s e l f . x
Código A.2: Implementação das unidades ocultas
1 # −∗− c o d i n g : u t f−8 −∗−
2 i m p o r t random
3 i m p o r t math
4 from l r u l e i m p o r t ∗
5
6 c l a s s U n i t ( o b j e c t ) :
7
8 d e f _ _ i n i t _ _ ( s e l f , N= 4 , L = 3 , l r u l e = H e b b i a n ) :
9 s e l f . l r u l e = l r u l e ( )
10 s e l f . w = [ random . r a n d i n t (−L , +L ) f o r _ i n r a n g e (N) ]
11 s e l f . L = L
12
13 d e f _ _ c a l l _ _ ( s e l f , x ) :
14 h = 0
15 f o r wi , x i i n z i p ( s e l f . w , x ) :
16 h = h + ( wi ∗ x i )
17 s e l f . o = s e l f . _ s g n ( h )
18 r e t u r n s e l f . o
19
20 d e f _ s g n ( s e l f , v ) :
21 i f v <= 0 :
22 r e t u r n −1
23 e l s e:
24 r e t u r n 1
25
26 d e f t r a i n ( s e l f , x , y ) :
27 f o r i i n r a n g e ( l e n ( s e l f . w) ) :
28 wi = s e l f . l r u l e ( s e l f . w[ i ] , x [ i ] , y , s e l f . o )
29 s e l f . w[ i ] = s e l f . _ a d j u s t ( wi )
30
31 d e f _ a d j u s t ( s e l f , wi ) :
32 i f wi > s e l f . L :
33 r e t u r n s e l f . L
34 e l i f wi < (−s e l f . L ) :
35 r e t u r n −s e l f . L
36 e l s e:
37 r e t u r n wi
Código A.3: Implementação das regras de aprendizado
1 # −∗− c o d i n g : u t f−8 −∗−
2 i m p o r t random
3 i m p o r t math
4
5 c l a s s L e a r n i n g R u l e :
6
7 d e f s t e p ( s e l f , y , o ) :
8 i f ( y ∗ o ) <= 0 :
9 r e t u r n 0
10 e l s e:
11 r e t u r n 1
12 13
14 c l a s s H e b b i a n ( L e a r n i n g R u l e ) :
15
16 d e f _ _ c a l l _ _ ( s e l f , w , x , y , o ) :
17 r e t u r n w + ( x ∗ y ) ∗ s e l f . s t e p ( y , o )
18 19
20 c l a s s A n t i H e b b i a n ( L e a r n i n g R u l e ) :
21
22 d e f _ _ c a l l _ _ ( s e l f , w , x , y , o ) :
23 r e t u r n w − ( x ∗ o ) ∗ s e l f . s t e p ( y , o )
24 25
26 c l a s s RandomWalk ( L e a r n i n g R u l e ) :
27
28 d e f _ _ c a l l _ _ ( s e l f , w , x , y , o ) :
29 r e t u r n w + x ∗ s e l f . s t e p ( y , o )
APÊNDICE B -- Implementação do protocolo de Criptografia Neural local
Código B.1: Implementação do Fluxo de Sincronização de duas TPMs localmente
1 from tpm i m p o r t ∗
2 i m p o r t t i m e
3
4 K = 3
5 N = 16
6 L = 3
7
8 c = 0
9 i = 0
10
11 p r i n t "---"
12 p r i n t "Sincronizando"
13 p r i n t "---"
14 A = T r e e P a r i t y M a c h i n e ( K , N , L , l r u l e )
15 B = T r e e P a r i t y M a c h i n e ( K , N , L , l r u l e )
16 s t a r t = t i m e . t i m e ( )
17
18 w h i l e A . w e i g h t s ( ) ! = B . w e i g h t s ( ) :
19 A . g e n e r a t e _ i n p u t s ( )
20 t = t + 1
21 A(A . x )
22 B (A . x )
23
24 i f A . a c t i v a t i o n ( B . y ) :
25 A . t r a i n (A . x )
26 B . t r a i n (A . x )
27
28 p r i n t t , "\t", ( t i m e . t i m e ( ) − s t a r t )
29 p r i n t "Sincronizado!"
APÊNDICE C -- Implementação do protocolo de Criptografia Neural em rede
Código C.1: Classe NeuralCryptography implementa os métodos herdáveis do protocolo de Criptografia Neural para o cliente e servidor
1 from t w i s t e d . i n t e r n e t . p r o t o c o l i m p o r t P r o t o c o l
2 from t w i s t e d . i n t e r n e t . p r o t o c o l i m p o r t F a c t o r y
3 from t w i s t e d . i n t e r n e t . e n d p o i n t s i m p o r t T C P 4 S e r v e r E n d p o i n t
4 from t w i s t e d . i n t e r n e t i m p o r t r e a c t o r
5 from C r y p t o . C i p h e r i m p o r t AES
6 from C r y p t o . Hash i m p o r t SHA256
7 from t h r e a d i n g i m p o r t T h r e a d
8 from tpm i m p o r t ∗
9 i m p o r t j s o n
10 i m p o r t b a s e 6 4
11
12 # Used t o a c c e s s t h e i n d e x i n t h e e x c h a n g e d m e s s a g e s
13 MESSAGE_TYPE = 0
14 MESSAGE = 1
15
16 # The t y p e s o f t h e m e s s a g e s e x c h a n g e d
17 TYPE_INPUTS = 0
18 TYPE_OUTPUT_SERVER = 1
19 TYPE_OUTPUT_CLIENT = 2
20 TYPE_ACK = 3
21 TYPE_TEST = 4
22 TYPE_TEST_OK = 5
23 TYPE_MESSAGE = 6
24
25 SYNC_THRESHOLD = 20
26 TEST_MESSAGE = 'SYNCED'
27
28 c l a s s N e u r a l C r y p t o g r a p h y ( P r o t o c o l ) :
29
30 d e f _ _ i n i t _ _ ( s e l f ) :
31 s e l f . tpm = T r e e P a r i t y M a c h i n e ( 4 , 3 ) ;
32 s e l f . c o u n t = 0
33 s e l f . s y n c r o n i z e d = F a l s e
34 s e l f . key = None
35 s e l f . c i p h e r = None
36
37 d e f s y n c r o n i z e r ( s e l f , d a t a ) :
38 d a t a = j s o n . l o a d s ( d a t a )
39 i f s e l f . c o u n t == SYNC_THRESHOLD :
40 s e l f . t e s t _ s y n c ( )
41 e l i f d a t a [ MESSAGE_TYPE ] == TYPE_INPUTS :
42 s e l f . r e c e i v e _ i n p u t s ( d a t a [MESSAGE ] )
43 e l i f d a t a [ MESSAGE_TYPE ] == TYPE_OUTPUT_SERVER :
44 s e l f . r e c e i v e _ o u t p u t _ f r o m _ s e r v e r ( d a t a [MESSAGE ] )
45 e l i f d a t a [ MESSAGE_TYPE ] == TYPE_OUTPUT_CLIENT :
46 s e l f . r e c e i v e _ o u t p u t _ f r o m _ c l i e n t ( d a t a [MESSAGE ] )
47 e l i f d a t a [ MESSAGE_TYPE ] == TYPE_ACK :
48 s e l f . r e c e i v e _ a c k ( )
49 e l i f d a t a [ MESSAGE_TYPE ] == TYPE_TEST :
50 s e l f . r e c e i v e _ t e s t ( d a t a [MESSAGE ] )
51 e l i f d a t a [ MESSAGE_TYPE ] == TYPE_TEST_OK :
52 s e l f . r e c e i v e _ t e s t _ o k ( )
53
54 d e f r e c e i v e _ i n p u t s ( s e l f , i n p u t s ) :
55 s e l f . tpm ( i n p u t s )
56 s e l f . t r a n s p o r t . w r i t e ( j s o n . dumps ( [ TYPE_OUTPUT_SERVER , s e l f . tpm . y ] ) )
57
58 d e f r e c e i v e _ o u t p u t _ f r o m _ s e r v e r ( s e l f , o u t p u t ) :
59 s e l f . t r a n s p o r t . w r i t e ( j s o n . dumps ( [ TYPE_OUTPUT_CLIENT , s e l f . tpm . y ] ) )
60 i f s e l f . tpm . y == o u t p u t :
61 s e l f . c o u n t += 1
62 s e l f . tpm . t r a i n ( )
63 e l s e:
64 s e l f . c o u n t = 0
65
66 d e f r e c e i v e _ o u t p u t _ f r o m _ c l i e n t ( s e l f , o u t p u t ) :
67 i f s e l f . tpm . y == o u t p u t :
68 s e l f . c o u n t += 1
69 s e l f . tpm . t r a i n ( )
70 e l s e:
71 s e l f . c o u n t = 0
72 s e l f . t r a n s p o r t . w r i t e ( j s o n . dumps ( [ TYPE_ACK , 0 ] ) )
73
74 d e f r e c e i v e _ a c k ( s e l f ) :
75 s e l f . tpm . g e n e r a t e _ i n p u t s ( )
76 s e l f . tpm ( s e l f . tpm . x )
77 s e l f . t r a n s p o r t . w r i t e ( j s o n . dumps ( [ TYPE_INPUTS , s e l f . tpm . x ] ) )
78
79 d e f s y n c e d ( s e l f ) :
80 r e t u r n s e l f . s y n c r o n i z e d
81
82 d e f t e s t _ s y n c ( s e l f ) :
83 s e l f . c o u n t = 0
84 s e l f . g e n e r a t e _ k e y ( )
85 s e l f . c i p h e r = AES . new ( s e l f . key , AES . MODE_CBC)
86
87 c i p h e r t e x t = s e l f . c i p h e r . e n c r y p t ( s e l f . pad ( TEST_MESSAGE . e n c o d e ('utf -8') ) )
88 c i p h e r t e x t = b a s e 6 4 . b 6 4 e n c o d e ( c i p h e r t e x t )
89 s e l f . t r a n s p o r t . w r i t e ( j s o n . dumps ( [ TYPE_TEST , c i p h e r t e x t ] ) )
90
91 d e f r e c e i v e _ t e s t ( s e l f , c i p h e r t e x t ) :
92 s e l f . g e n e r a t e _ k e y ( )
93 s e l f . c i p h e r = AES . new ( s e l f . key , AES . MODE_CBC)
94 c i p h e r t e x t = b a s e 6 4 . b 6 4 d e c o d e ( c i p h e r t e x t )
95 p l a i n t e x t = s e l f . c i p h e r . d e c r y p t ( c i p h e r t e x t )
96 p l a i n t e x t = s e l f . u n p a d ( p l a i n t e x t )
97 i f p l a i n t e x t == TEST_MESSAGE :
98 s e l f . t r a n s p o r t . w r i t e ( j s o n . dumps ( [ TYPE_TEST_OK , TEST_MESSAGE ] ) )
99 s e l f . s y n c r o n i z e d = T r u e
100 p r i n t s e l f . tpm . w e i g h t s ( )
101 s e l f . s t a r t _ s e r v i c e ( )
102 e l s e:
103 s e l f . t r a n s p o r t . w r i t e ( j s o n . dumps ( [ TYPE_ACK , 0 ] ) )
104
105 d e f r e c e i v e _ t e s t _ o k ( s e l f ) :
106 s e l f . s y n c r o n i z e d = T r u e
107 s e l f . s t a r t _ s e r v i c e ( )
108 p r i n t s e l f . tpm . w e i g h t s ( )
109
110 d e f g e n e r a t e _ k e y ( s e l f ) :
111 s e e d = s t r ( s e l f . tpm . w e i g h t s ( ) )
112 s h a = SHA256 . new ( )
113 s h a . u p d a t e ( s e e d )
114 s e l f . key = s h a . d i g e s t ( )
115 r e t u r n s e l f . key
116
117 d e f pad ( s e l f , s ) :
118 BS = 16
119 r e t u r n s + ( BS − l e n ( s ) % BS ) ∗ c h r ( BS − l e n ( s ) % BS )
120
121 d e f u n p a d ( s e l f , s ) :
122 r e t u r n s [0:−o r d ( s [−1 ] ) ]
123
124 d e f c a l l ( s e l f , t a r g e t , a r g s ) :
125 s e l f . t h r e a d = T h r e a d ( t a r g e t = t a r g e t , a r g s = ( a r g s ) )
126
127 d e f r e c e i v e ( s e l f , t a r g e t ) :
128 s e l f . d a t a _ r e c e i v e d = t a r g e t
129
130 d e f s t a r t _ s e r v i c e ( s e l f ) :
131 s e l f . t h r e a d . s t a r t ( )
132
133 d e f r e c e i v e d ( s e l f , d a t a ) :
134 d a t a = j s o n . l o a d s ( d a t a )
135 c i p h e r t e x t = d a t a [MESSAGE]
136 c i p h e r t e x t = b a s e 6 4 . b 6 4 d e c o d e ( c i p h e r t e x t )
137 p l a i n t e x t = s e l f . c i p h e r . d e c r y p t ( c i p h e r t e x t )
138 p l a i n t e x t = s e l f . u n p a d ( p l a i n t e x t )
139 s e l f . d a t a _ r e c e i v e d ( p l a i n t e x t )
140
141 d e f s e n d _ m e s s a g e ( s e l f , d a t a ) :
142 c i p h e r t e x t = s e l f . c i p h e r . e n c r y p t ( s e l f . pad ( d a t a ) )
143 c i p h e r t e x t = b a s e 6 4 . b 6 4 e n c o d e ( c i p h e r t e x t )
144 s e l f . t r a n s p o r t . w r i t e ( j s o n . dumps ( [ TYPE_MESSAGE , c i p h e r t e x t ] ) )
Código C.2: Classe NeuralCryptographyClient implementa o cliente na sincronização em rede
1 from t w i s t e d . i n t e r n e t . p r o t o c o l i m p o r t P r o t o c o l
2 from t w i s t e d . i n t e r n e t . p r o t o c o l i m p o r t F a c t o r y
3 from t w i s t e d . i n t e r n e t . e n d p o i n t s i m p o r t T C P 4 C l i e n t E n d p o i n t
4 from t w i s t e d . i n t e r n e t i m p o r t r e a c t o r
5 from p r o t o c o l i m p o r t N e u r a l C r y p t o g r a p h y
6 from tpm i m p o r t T r e e P a r i t y M a c h i n e
7 i m p o r t j s o n
8
9 c l a s s N e u r a l C r y p t o g r a p h y C l i e n t ( N e u r a l C r y p t o g r a p h y ) :
10
11 d e f _ _ i n i t _ _ ( s e l f ) :
12 N e u r a l C r y p t o g r a p h y . _ _ i n i t _ _ ( s e l f )
13 s e l f . c a l l ( t a r g e t = c h a t L o o p , a r g s = ( s e l f , ) )
14 s e l f . r e c e i v e ( t a r g e t = p r i n t e r )
15
16 d e f d a t a R e c e i v e d ( s e l f , d a t a ) :
17 i f n o t s e l f . s y n c e d ( ) :
18 s e l f . s y n c r o n i z e r ( d a t a )
19 e l s e:
20 s e l f . r e c e i v e d ( d a t a )
21
22 d e f c o n n e c t i o n M a d e ( s e l f ) :
23 s e l f . r e c e i v e _ a c k ( )
24 25
26 d e f c h a t L o o p ( c h a t ) :
27 w h i l e T r u e :
28 c h a t . s e n d _ m e s s a g e ( s t r ( r a w _ i n p u t ( ) ) )
29
30 d e f p r i n t e r ( m e s s a g e ) :
31 p r i n t m e s s a g e
32
33 # I n i c i a l i z a c l a s s e
34 f a c t o r y = F a c t o r y ( )
35 f a c t o r y . p r o t o c o l = N e u r a l C r y p t o g r a p h y C l i e n t
36 e n d p o i n t = T C P 4 C l i e n t E n d p o i n t ( r e a c t o r , "localhost", 1 9 8 4 )
37 e n d p o i n t . c o n n e c t ( f a c t o r y )
38 r e a c t o r . r u n ( )
Código C.3: Classe NeuralCryptographyServer implementa o servidor na sincronização em rede
1 from t w i s t e d . i n t e r n e t . p r o t o c o l i m p o r t P r o t o c o l
2 from t w i s t e d . i n t e r n e t . p r o t o c o l i m p o r t F a c t o r y
3 from t w i s t e d . i n t e r n e t . e n d p o i n t s i m p o r t T C P 4 S e r v e r E n d p o i n t
4 from t w i s t e d . i n t e r n e t i m p o r t r e a c t o r
5 from p r o t o c o l i m p o r t N e u r a l C r y p t o g r a p h y
6 from tpm i m p o r t T r e e P a r i t y M a c h i n e
7 i m p o r t j s o n
8
9 c l a s s N e u r a l C r y p t o g r a p h y S e r v e r ( N e u r a l C r y p t o g r a p h y ) :
10
11 d e f _ _ i n i t _ _ ( s e l f ) :
12 N e u r a l C r y p t o g r a p h y . _ _ i n i t _ _ ( s e l f )