Click here to Skip to main content
13,548,587 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


60 bookmarked
Posted 17 Aug 2009
Licenced CPOL

Neural Cryptography

, 29 Aug 2009
Rate this:
Please Sign up or sign in to vote.
This article presents a new cryptography algorithm based on neural networks. Here, you can find some theory and a demo project.

1. Abstract

There are many Cryptography algorithms nowadays. Some of them are more secure, some less. All those algorithms can be split into symmetric or asymmetric cryptography. In symmetric cryptography, the sender and receiver use a shared key to encode and decode plain text. In asymmetric algorithms, users have their own private and public keys. There are some advantages and disadvantages in both methods in terms of speed and level of security. I will just say that symmetric algorithms are a lot faster than asymmetric ones. But they do need a shared key. How can we get a shared key via a public channel and protect it against opponents? There are many ways to do this, which are more or less effective, but I want to offer a rather new and absolutely secure method: neural cryptography.

2. Requirements

  • Familiarity with Delphi
  • Some math knowledge about basic neural networks

3. Introduction

There are two guys: Alex and Boris, and an insecure channel (for example, ICQ). They want to send some top-secret information to each other. Also, they can't use RSA-like asymmetric algorithms, and they can't meet to create a secret key for their messages. What should they do? The answer is to build neural networks, one for each. Then, they should synchronize their networks, and the weights will be the secret key. This article implements a basic neural cryptography algorithm and a demo project written in Delphi to show its fantastic effect. It would be interesting for developers, cryptoanalytics, and those people who want to make their communication secure.

4. Background

This part explains some of the neural network theories you need to understand in Section 5.

Here is a simple neural network developed by Rosenblat in 1968. It consists of an input vector X, a hidden layer Sigma s, a weights coefficients W between the input vector and the hidden layer, and an activation procedure ? that counts the result value t. Let's call such a neural network a neural machine. It can be described by three parameters: K, the number of hidden neurons, N, the number of input neurons connected to each hidden neuron, and L, the maximum value for weight {-L..+L}. Two partners have the same neural machines. To synchronize them, they should execute such an algorithm:


To count the output value, we use a simple method:

How do we update the weights? We update the weights only if the output values of the neural machines are equal. There are three different rules:

Hebbian learning rule

Anti-Hebbian learning rule

Random-walk learning rule

Here, Theta is a special function. Theta(a, b)=0 if a<>b; else Theta=1. The g(...) function keeps the weights in the range -L..+L. x is the input vector and w is the weights vector. After the machines are synchronized, their weights are equal: we can use them for constructing a shared key. In [3], there is a lot of information about the attacks on this algorithm. I just want to say here that it is impossible to hack it.

5. Implementation

In this section, I describe how to program neural machines and will show how to use the Delphi unit NeuroCrypt.pas.

The main object in this unit is tTPM (TPM - Tree Parity Machine in [3]). It contains two vectors: H and W. "H" is used for internal operations during result value counting. "W" contains weights. There are also four integer values: K, L, N, and TPOutput. Here is the interface of the tTPM, tVector, and tInputVector objects:

tVector = array of integer;
tTPM = object
  Procedure InitAll;
  Procedure CountResult(X:tVector);
  Procedure UpdateWeight(X:tVector);
  Procedure RandomWeight;
  Function VectorValue:integer;
  X: TVector;
  Procedure FormRandomVector(k,n:integer);

I think the names of the procedures say for themselves what they do. You can also download the source code from this site, and it's not necessary to explain it. Here I just show how to use it. First of all, we initialize the neural machine's properties:

A: tTPM;
with A do

Then, in every iteration, we should produce the input vector, the count output value, and send them to the partner B. "B" should do the same.

inp: tInputVector;
if a.TPOutput=b.TPOutput then

Here is a screenshot of the demo project based on NeuroCrypt:


6. Future Work

  • Solve the problem of man-in-middle attacks when a man can change messages
  • Build an add-on to ICQ/MSN client to secure messages
  • Add file transfer procedures

7. References

  • [1] A New Technique on Neural Cryptography with Securing of Electronic Medical Records in Telemedicine System – N.Prabakaran, Department of Mathematics, Anna University, 2008
  • [2] Cryptography based on delayed chaotic neural networks – Wenwu Yu, Department of Mathematics, Southeast University, 2006
  • [3] Neural Synchronization and Cryptography — Andreas Ruttor. PhD thesis, Bayerische Julius-Maximilians-Universität Würzburg, 2006

8. History

  • 18th August, 2009: Initial post.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Russian Federation Russian Federation
Moscow State University of Economics, Statistics and Informatics (MESI) - diploma at 2010
Interesting in robot's navigation, machine learning, neural networks, 3D-graphics, cryptography
Delphi - for fun
C# - for work

You may also be interested in...

Comments and Discussions

Questionerror at tTPM=object Pin
Vamsi Sravan29-Feb-16 21:38
memberVamsi Sravan29-Feb-16 21:38 
QuestionWhat textboks and papers you considered while making this project!!!!! Pin
Member 995731111-Aug-13 0:32
memberMember 995731111-Aug-13 0:32 
GeneralMy vote of 5 Pin
Peter_Second8-Apr-12 11:37
memberPeter_Second8-Apr-12 11:37 
QuestionA question for the author Pin
lokenxo8-Mar-12 9:28
memberlokenxo8-Mar-12 9:28 
AnswerRe: A question for the author Pin
MohammadKiani220-Jun-13 4:25
memberMohammadKiani220-Jun-13 4:25 
GeneralMy vote of 5 Pin
Anand Inasu Chittilappilly26-Dec-11 22:25
memberAnand Inasu Chittilappilly26-Dec-11 22:25 
GeneralMy vote of 5 Pin
Filip D'haene13-Nov-11 10:11
memberFilip D'haene13-Nov-11 10:11 
GeneralHI Pin
marsela2710-Jun-11 21:45
membermarsela2710-Jun-11 21:45 
GeneralHi, Cybertrone. [modified] Pin
BodomAnka11-Apr-11 13:16
memberBodomAnka11-Apr-11 13:16 
GeneralHi Cybertrone, Pin
pramodpavithran6-Feb-11 18:05
memberpramodpavithran6-Feb-11 18:05 
Generalfound some vestigial code Pin
Kalmah14-Oct-10 16:55
memberKalmah14-Oct-10 16:55 
i went through the source code but i haven't been able to figure out the following...

[line 61]
function KorrFichn(A,B:tVector):real;

[line 79]
function power(t,k:int64):int64;

[line 158]
function tTPM.VectorValue: integer;

the above functions are never used in the program flow. are they just lying there for possible future implementation only or are they actually being used. i'm confused here.

[line 42]
[line 84]

i don't understand where the actual implementation of 'vec' is used in the overall program.

[line 87]

this will equal to a.L * a.L * a.L * a.L * a.N * a.K.
[line 89] "for i:=1 to max do" forloop is used.
can someone pls make me clear on the theory behind the formula of 'max' variable and why it's for-looped 'max' number of times using that very formula.

Generalgreat work Pin
Member 3940511-Apr-10 0:10
memberMember 3940511-Apr-10 0:10 
Generalreply me.......... Pin
gspsvsl20-Mar-10 22:09
membergspsvsl20-Mar-10 22:09 
Generalgood work Pin
sskgd12-Mar-10 19:38
membersskgd12-Mar-10 19:38 
GeneralAn Excellent Concept Pin
_Khallaf29-Aug-09 8:47
member_Khallaf29-Aug-09 8:47 
GeneralRe: An Excellent Concept Pin
CyberTrone30-Aug-09 9:02
memberCyberTrone30-Aug-09 9:02 
GeneralRe: An Excellent Concept Pin
BodomAnka12-Apr-11 3:45
memberBodomAnka12-Apr-11 3:45 
Generalwell Pin
konikula27-Aug-09 2:28
memberkonikula27-Aug-09 2:28 
GeneralRe: well Pin
CyberTrone27-Aug-09 6:22
memberCyberTrone27-Aug-09 6:22 
GeneralRe: well Pin
konikula27-Aug-09 8:34
memberkonikula27-Aug-09 8:34 
GeneralRe: well Pin
konikula27-Aug-09 10:10
memberkonikula27-Aug-09 10:10 
GeneralRe: well Pin
CyberTrone27-Aug-09 17:47
memberCyberTrone27-Aug-09 17:47 
GeneralRe: well Pin
konikula27-Aug-09 17:56
memberkonikula27-Aug-09 17:56 
GeneralRe: well Pin
CyberTrone28-Aug-09 1:25
memberCyberTrone28-Aug-09 1:25 
GeneralRe: well Pin
konikula28-Aug-09 3:10
memberkonikula28-Aug-09 3:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04-2016 | 2.8.180515.1 | Last Updated 29 Aug 2009
Article Copyright 2009 by CyberTrone
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid