Embodiment
Below in conjunction with the drawings and specific embodiments, further illustrate technical scheme of the present invention.
The present invention can produce 64 2 system random number seeds.Its principle is:
Polaroid A and B all set 2 groups of bases (4 directions), be respectively straight line base (vertical, level) and diagonal angle base (upper left is to bottom right, and upper right is to lower-left), each polarizer only switches on this four direction, and every group of base both direction respectively correspondence is defined as 0 and 1.
Suppose that Alice and Bob both sides will communicate.First Alice utilizes a randomizer to generate one and is greater than 10 strings that need 2 times of key lengths, and then polaroid A is selected arbitrarily a direction of one group of base every the time of △ T, produces the polarised light that represents corresponding bit digital.The polarizer B accordingly a direction in one group of base of random selection of the time of △ T passes through the polarised light after A.Now, Bob, by analyzing the measured light intensity of light intensity receptor B, produces key.Concrete analysis situation is as follows:
1. polaroid A is identical with the selected base of polarizer B.The light intensity of now experiencing by light intensity receptor B is 1/2I0+1/2I or 1/2I, thereby can judge the corresponding bit digital that A sends.
2. polaroid A is different from the selected base of polarizer B, and the light intensity of now experiencing by light intensity receptor B is between 2 kinds of situations 1..
At this moment Bob by the analysis to light intensity receptor B data, retains the identical part of base, casts out the part that base is not identical, and to define the position that base is identical be significance bit, using the numeral in significance bit as key.Bob knows the numeral that in all significance bits, A sends.Meanwhile, Bob sends to Alice in order by his each base of selecting, and Alice just also can know the correct base of Bob, and both sides now just can obtain same key.64 random numbers that the present invention produces by polarised light, as seed, by seed expansion, produce the random number of 128 by hash algorithm (having applied SHA1 algorithm in native system), the key that this random number is encrypted as follow-up AES.MD5 is MessagedigestAlgorithm5(Message Digest 5) abbreviation, through MD2, MD3 and MD4, develop.It can be transformed into the byte serial of a random length the large integer of one fixed length.
One, hardware components
Hardware components is divided into light intensity and experiences module and motor control module.
Light intensity is experienced module
The present invention has applied BH1759FVI module, and circuit diagram as shown in Figure 1.PD(Photo diode with approximately human eye response wherein) for approaching the photodiode of people's ophthalmic reaction; AMP is that integrated computation amplifies Interface(logic+IC interface) for luminous intensity, calculate and I2C bus interface, comprise lower column register: data register can be PD voltage by PD current conversion; ADC is analog-to-digital conversion, can obtain 16 bit digital data; Logic+ICInterface(logic+IC interface) for luminous intensity is calculated and I2C bus interface, comprise lower column register: data register → light intensity data is deposited, Measuring Time register → time measurement data are deposited, and initial value is respectively " 0000_0000_0000_0000 " and " 0100_0101 "; OSC is internal oscillator (clock frequency representative value: 320kHz).This clock is internal logic clock.This module has higher resolution, can cross detection intensity variation (1-65535lx) in a big way.This transducer is connected with single-chip microcomputer, by serial ports, obtains the light intensity that light intensity receptor detects.Continuous H resolution model 2 times, Measuring Time is 120ms, light intensity resolution 0.5lx.
Fig. 2 is its spectral response, by this spectrum, should be able to find out that it all has response at 400-700nm wavelength mutually, can feed back preferably the light intensity of visible ray.
Fig. 3 is its light source dependency characteristic, can see, this transducer is all higher to the resolving power of most of light source, wherein the highest with the resolving power of incandescence, Krypton light and halogen light.In the present invention, selected the most widely used incandescent light.
Its core code is as follows:
In transfer of data, applied I2C bus protocol, this is a kind of twin wire universal serial bus, for connecting microcontroller and ancillary equipment thereof.It is a kind of bus standard that microelectronics Control on Communication field extensively adopts.It is a kind of special shape of synchronous communication, has interface line few, and control mode is simple, and device package form is little, and traffic rate is compared with advantages of higher.Fig. 4 is the transfer of data sequential chart in I2C agreement.
Motor control module
The present invention adopts FL42STH38-0806A type stepping motor (rated voltage 6v, 1.8 ° of step angles).Stepping motor rotor is permanent magnet, and when electric current flows through stator winding, stator winding produces a Vector Magnetic Field.This magnetic field can rotate an angle by rotor driven, makes the pair of magnetic field direction of rotor consistent with the magnetic direction of stator.An angle of Vector Magnetic Field rotation when stator.Rotor is also along with this magnetic field turns an angle.Electric pulse of every input, motor rotates an angle and takes a step forward.The angular displacement of its output is directly proportional to the umber of pulse of input, rotating speed is directly proportional to pulse frequency.The order that changes winding energising, motor will reverse.Therefore can pass through Single-chip Controlling pulse number (with pilot angle displacement), thereby reach the object of accurate location; Simultaneously can be by control impuls frequency (to control speed and the acceleration of electric machine rotation), thus reach the object of speed governing.
In the present invention, stepping motor is connected with polarizer, by single-chip microcomputer, produces pulse control step electric machine rotation, can control comparatively accurately polarizer and turn to corresponding base.
Kernel program is as follows:
The definition of //L298 input control end
unsigned?char?code
F_Rotation[8]={ 0x3a, 0x28,0x39,0x11,0x35,0x24,0x36,0x12}; // forward form half step mode
If // stepping motor is 360 degree that take a round so of 1.8 degree, step mode needs 200 step half step modes to need 400 steps oneself to design according to stepping motor parameter entirely
The control of stepping motor has been applied and take the step motor control plate that L298N chip (pin figure is as Fig. 5) is core, and inside comprises 4 channel logic drive circuits.Be the special purpose driver of a kind of two-phase and four phase motors, the high-voltage large current that includes two the H bridges bridge driver of enjoying a double blessing, receives standard TTL logic level signal, can drive 46V, the motor below 2A.Its pin arrangements as shown in Figure 5, can draw separately and be connected current sampling resistor device with 15 pin by 1 pin, forms current sensing signal.
L298 can drive 2 motors, connects respectively 2 motor between OUTl, OUT2 and OUT3, OUT4.5,7,10,12 pin connect input control level, control the rotating of motor, ENA, and ENB connects control Enable Pin, controls the stall of motor.
WiFi communication
WiFi(Wireless Fidelity) claim again 802.11b standard, have that transmission speed is higher, coverage is long a little.Meanwhile, it also with existing various 802.11DSSS hardware compatibilities.
In the present invention, communicating pair communicates by WiFi, carries out the related works such as significance bit transmission, file transfer.
Two, software section
Software section is divided into serial communication modular, random number generation module, significance bit analysis module, AES encrypting module, MD5 cipher key expansion module and communication module.
Serial communication modular
Serial line interface is a kind ofly can be converted to continuous serial data stream and send accepting parallel data character from CPU, the serial data stream of acceptance can be converted to the device that parallel data character is supplied with CPU simultaneously.The present invention is based on RS232 serial ports and carry out data communication.
Serial communication of the present invention operates serial ports accordingly by Employ Windows API Function, as opens serial ports, sends data, accepts data, serial ports initialization setting, closes the operations such as serial ports.
Win32API (comprising: Windows9x as Microsoft32 bit platform, WindowsNT3.1/4.0/5.0, WindowsCE) application programming interface, it is the foundation stone of constructing all 32-bit Windows platforms, and all application programs of moving on windows platform can be called these functions.Use Windows CommAPI under Windows environment, to carry out serial port programming, need not directly operate hardware, and call by language such as VC, VB and Delphi, greatly facilitate the processing to data.In the Windows system of 32, serial communication is as file process, the operations such as opening, close, read, write that operation of serial-port is generally.
In the present invention, intercommunication has adopted asynchronous communication model, and asynchronous communication is when sending character, and the time slot between the character sending can be arbitrarily.Transmitting terminal can start to send character at any time, only need add start bit and position of rest in the beginning of each character and the place of end, to receiving terminal can correctly be got off each receive character.Internal processor is after having completed corresponding operation, by the mechanism of a readjustment, so that the character that notice transmitting terminal sends has obtained reply.Asynchronous communication efficiency of transmission in limited channel is high, and shortcoming is that equipment is complicated, channel utilization lower (because the expense proportion of start bit and position of rest is larger).
Asynchronous communication can be also to using frame as sending unit (as Fig. 6).Receiving terminal must be carried out the preparation of received frame at any time.The stem of frame must be provided with frame and delimit.Frame is delimited and is also comprised the end position of determining frame.This has two kinds of methods.A kind of is that afterbody at frame is provided with the end that certain special bit combination is carried out marker frames; The another kind of field of frame length that is provided with in frame stem.Under this pattern, do not require receiving-transmitting sides clock strict conformance, easily realize, just need to add checking position, efficiency of transmission is not high.
Random number generation module
In java, we produce a randomizer by java.util.Random class, and then produce 10 strings that we need.
Significance bit analysis module
Significance bit analysis is by polarised light, to obtain the core operation of key.System can finally obtain corresponding secret key by significance bit analysis.Be described in detail as follows.
First analyze the different conditions of two polarizers.If polaroid A is identical with the selected base of polarizer B, the light intensity of now experiencing by light intensity receptor B is 1/2I0+1/2I or 1/2I, thereby can judge the corresponding bit digital that A sends; If polaroid A is different from the selected base of polarizer B, the light intensity of now experiencing by light intensity receptor B is between 2 kinds of situations 1..
Significance bit routine analyzer by light intensity receptor data analysis, retains the identical part of base, casts out the part that base is not identical, and to define the position that base is identical be significance bit.Program, using the corresponding numeral in significance bit as key, completes the work that significance bit is analyzed afterwards.
AES encrypts
AES ciphering process is to operate on the byte matrix of 4 * 4, and this matrix is called again " state (state) ", and its initial value is exactly a clear packets (in matrix, an element size is exactly a Byte in clear packets).Ri jndael enciphered method is because supporting larger grouping, and the visual situation of its matrix line number increases.During encryption, each is taken turns AES encryption cycle (except last is taken turns) and all comprises 4 steps:
(1) byte substitution (Sub Bytes)
By a nonlinear replacement function, by the mode of tabling look-up, each byte is replaced to corresponding byte.Each byte in matrix is changed by the S-box of 8.S-box is relevant with the inverse element on GF (28), has good nonlinear characteristic.For fear of the attack of simple algebraic property, S-box combines multiplicative inverse and a reversible affine transformation matrix construction forms.During this external construction S-box, deliberately avoid fixing point and anti-fixing point, with the result of S-box replacement byte, can be equivalent to wrong row's result.
(2) row displacement (Shift Rows)
Each line in matrix is carried out to circulating displacement.In this step, in matrix, each byte of every a line orientation left that circulates is moved.Displacement is along with line number increases progressively and increase progressively.Shift Rows is the step for each line operation of matrix.In this step, each provisional capital is certain side-play amount of cyclic shift left.In AES (128 of packet sizes), the first row remains unchanged, and each byte in the second row is loopy moving one lattice left.In like manner, the third line and fourth line left the side-play amount of cyclic shift be just 2 and 3 respectively.128 identical with the pattern of the cyclic shift that is grouped in this step of 192.After space displacement, in matrix, each perpendicular row, is all that the element in each different lines in input matrix forms.In the version of Ri jndael algorithm, side-play amount and AES have a little difference: for the grouping of 256 of length, the first row still remains unchanged, and the side-play amount of the second row, the third line, fourth line is respectively 1 byte, 3 bytes, 4 bytes.In addition, Shift Rows operating procedure at Ri jndael with identical in AES.
(3) row mix (Mix Columns)
Operation for each craspedodrome in abundant hybrid matrix.In this step, four bytes of every a line are interosculated by linear transformation.Four coefficients that element is used as respectively of every a line, merge and are a multinomial in GF (28), then this multinomial and a fixing multinomial are multiplied each other under mould.This step also can be considered the matrix multiplication under Ri jndael finite field.Row mixed function receives the input of 4 bytes, exports 4 bytes, and the byte of each input can impact four bytes of output.Because mixing two steps, this journey displacement and row provide diffusivity for this cryptographic system.
(4) key adds (Add Round Key)
Each byte in matrix is done XOR computing with round key (round key); Each sub-key is produced by key generation scheme.In each encryption cycle, all can produce one group of round key (producing by Ri jndael key generation scheme) by master key, each round key size is the same with original matrix, and makes XOR (⊕) addition with each corresponding byte in original matrix.
MD5 cipher key spreading
64 seeds that produce by polarised light carry out cipher key spreading by the MD5 algorithm in hash algorithm and expand final 128 keys encrypting as AES.
Detailed process is as follows:
(1) cover
First information is filled, 1 and several 0 of filling below in information make its byte length equal 448 to the result of 512 complementations.
(2) complement certificate
With the original length B of the numeral data of 64, two 32 figure places for B? represent.At this moment, just to be filled up into length be the multiple of 512 to data.
(3) initialization MD5 parameter
MD5 is carried out to initialization, in MD5 with four 32 numeric parameters that are known as link variable, they are respectively: A=0x01234567, B=0x89abcdef, C=0xfedcba98, D=0x76543210.
(4) four-wheel loop computation
Start to enter the four-wheel loop computation of algorithm.The number of times of circulation is the number of 512 information block in information.Four link variables copy in other four variablees above: A is to a, and B is to b, and C is to c, and D is to d.Major cycle has four-wheel, and the first round is carried out 16 operations.Each operation in a, b, c and d wherein three do a nonlinear function computing, then acquired results is added to the 4th variable, then by indefinite number of acquired results displacement to the right, and one of adds in a, b, c or d.Finally by this result, one of replace in a, b, c or d.Below four nonlinear functions using in each operation (every take turns one).
f(x,y,z)=(x&y)|((~x)&z)
g(x,y,z)=(xz)|(y&(~z))
h(x,y,z)=x^y^z
i(x,y,z)=y^(x|(~z))
(wherein: " & " is and computing, and " | " is exclusive disjunction, and "~" is inverse, and " ^ " is XOR, they are all bit arithmetic symbols.)
The explanation of these four functions: if the corresponding position of x, y and z is independent and uniformly, each of result should be also independent and uniformly so.F is the function of a bitwise operation.That is, if x, y so, otherwise z.Function h is odd even operator by turn.Suppose that mj represents j the subgroup (from 0 to 15) of message, ti is the constant in I step, and <<<s represents ring shift left s position, and four kinds are operating as:
Ff (a, b, c, d, mj, s, ti) represents a=b+ ((a+ (f (b, c, d)+mj+ti) <<<s)
Gg (a, b, c, d, mj, s, ti) represents a=b+ ((a+ (g (b, c, d)+mj+ti) <<<s)
Hh (a, b, c, d, mj, s, ti) represents a=b+ ((a+ (h (b, c, d)+mj+ti) <<<s)
Ii (a, b, c, d, mj, s, ti) represents a=b+ ((a+ (i (b, c, d)+mj+ti) <<<s)
This four-wheel (64 step) is:
The first round
FF(a,b,c,d,M0,7,0xd76aa478)
FF(d,a,b,c,M1,12,0xe8c7b756)
FF(c,d,a,b,M2,17,0x242070db)
FF(b,c,d,a,M3,22,0xc1bdceee)
FF(a,b,c,d,M4,7,0xf57c0faf)
FF(d,a,b,c,M5,12,0x4787c62a)
FF(c,d,a,b,M6,17,0xa8304613)
FF(b,c,d,a,M7,22,0xfd469501)
FF(a,b,c,d,M8,7,0x698098d8)
FF(d,a,b,c,M9,12,0x8b44f7af)
FF(c,d,a,b,M10,17,0xffff5bb1)
FF(b,c,d,a,M11,22,0x895cd7be)
FF(a,b,c,d,M12,7,0x6b901122)
FF(d,a,b,c,M13,12,0xfd987193)
FF(c,d,a,b,M14,17,0xa679438e)
FF(b,c,d,a,M15,22,0x49b40821)
Second takes turns
GG(a,b,c,d,M1,5,0xf61e2562)
GG(d,a,b,c,M6,9,0xc040b340)
GG(c,d,a,b,M11,14,0x265e5a51)
GG(b,c,d,a,M0,20,0xe9b6c7aa)
GG(a,b,c,d,M5,5,0xd62f105d)
GG(d,a,b,c,M10,9,0x02441453)
GG(c,d,a,b,M15,14,0xd8a1e681)
GG(b,c,d,a,M4,20,0xe7d3fbc8)
GG(a,b,c,d,M9,5,0x21e1cde6)
GG(d,a,b,c,M14,9,0xc33707d6)
GG(c,d,a,b,M3,14,0xf4d50d87)
GG(b,c,d,a,M8,20,0x455a14ed)
GG(a,b,c,d,M13,5,0xa9e3e905)
GG(d,a,b,c,M2,9,0xfcefa3f8)
GG(c,d,a,b,M7,14,0x676f02d9)
GG(b,c,d,a,M12,20,0x8d2a4c8a)
Third round
HH(a,b,c,d,M5,4,0xfffa3942)
HH(d,a,b,c,M8,11,0x8771f681)
HH(c,d,a,b,M11,16,0x6d9d6122)
HH(b,c,d,a,M14,23,0xfde5380c)
HH(a,b,c,d,M1,4,0xa4beea44)
HH(d,a,b,c,M4,11,0x4bdecfa9)
HH(c,d,a,b,M7,16,0xf6bb4b60)
HH(b,c,d,a,M10,23,0xbebfbc70)
HH(a,b,c,d,M13,4,0x289b7ec6)
HH(d,a,b,c,M0,11,0xeaa127fa)
HH(c,d,a,b,M3,16,0xd4ef3085)
HH(b,c,d,a,M6,23,0x04881d05)
HH(a,b,c,d,M9,4,0xd9d4d039)
HH(d,a,b,c,M12,11,0xe6db99e5)
HH(c,d,a,b,M15,16,0x1fa27cf8)
HH(b,c,d,a,M2,23,0xc4ac5665)
Fourth round
II(a,b,c,d,M0,6,0xf4292244)
II(d,a,b,c,M7,10,0x432aff97)
II(c,d,a,b,M14,15,0xab9423a7)
II(b,c,d,a,M5,21,0xfc93a039)
II(a,b,c,d,M12,6,0x655b59c3)
II(d,a,b,c,M3,10,0x8f0ccc92)
II(c,d,a,b,M10,15,0xffeff47d)
II(b,c,d,a,M1,21,0x85845dd1)
II(a,b,c,d,M8,6,0x6fa87e4f)
II(d,a,b,c,M15,10,0xfe2ce6e0)
II(c,d,a,b,M6,15,0xa3014314)
II(b,c,d,a,M13,21,0x4e0811a1)
II(a,b,c,d,M4,6,0xf7537e82)
II(d,a,b,c,M11,10,0xbd3af235)
II(c,d,a,b,M2,15,0x2ad7d2bb)
II(b,c,d,a,M9,21,0xeb86d391)
Constant ti is illustrated in i step, and ti is the integer part of 42949672963abs (sin (i)), 4,294,967,296 32 powers that equal 2, and the unit of i is radian.After all these complete, A, B, C, D are added respectively to a, b, c, d.Then by next grouped data, continue executing arithmetic, last output is the cascade of A, B, C and D.
Communication software
Communication module is one to be similar to the intercommunication program of qq, and both sides can communicate and file transfer by this program.Software integral body is write by Java language, has used NetBeans to carry out the design at interface, based on AWT kit with take that it completes the design work at relevant interface as basic Swing kit.
This communication software program comprises authentication, authentication, the communication of single-chip microcomputer-PC and several parts of communicating by letter.
Authentication: first need to carry out authentication when using this program.Program and a database association, in database, storing all users' identity such as account number cipher, IP address (each user's IP address is fixing in this local area network (LAN)) so program can reading database in user identity, only have in account number cipher and database and match and can login successfully.After logining successfully, this user continuous heartbeat packet that sends in this local area network (LAN) (all use is per family in this local area network (LAN)) represents that it is online.If do not receive, heartbeat packet represents that this user rolls off the production line.
Authentication: show other online users after authentication, can select wherein user arbitrarily to ask communication, now this subscriber computer will send a request message on Requested Party IP address.If communication is rejected, to requesting party, send unaccepted information, communication can not be carried out; If communication request is allowed to, to requesting party, returns to request and allow signal.
Single-chip microcomputer-PC communication: program sends an initial signal to single-chip microcomputer after communication is allowed to.Single-chip microcomputer is started working, and produces random number and the selected base of polarizer, and the base of its selection is passed to relative users.After this single-chip microcomputer starts control step electric machine rotation to drive polarizer rotation, obtains key seed.
Communication: just can enter communication interface after both sides all obtain seed.Communication interface has comprised communications records (can several nearest intercommunication information of instant playback), has sent frame, has sent button, historical record button.Both sides can communicate in this page, and the content of communication is by passing through AES encipheror, and key is by the key obtaining after MD5 cipher key spreading.Automatically there is the plaintext of the plaintext of transmission, ciphertext, acceptance, ciphertext respectively in a txt text in program, user can watch at any time.
Three, system contrive equipment
System and device framework is as shown in Fig. 3 .14.System is by carrying out analytical calculation to a branch of light intensity by the light after the polarizer of two rotations, produce the key of communicating by letter between Alice machine and Bob machine, by this key, the content of intercommunication is encrypted to rear transmission, thereby has ensured the fail safe of intercommunication.
Figure 11 is contrive equipment framework, and Chip Microcomputer A is connected with Alice computer, polaroid A, and single-chip microcomputer B is connected with Bob computer, polarizer B, and while Alice can carry out Wifi with Bob and communicate by letter.One constant light source is arranged at device top, and can send light intensity constant is the light of I0.Light by rotatable polaroid A and polarizer B after, its intensity can be measured by light intensity receptor B.The light intensity of simultaneously establishing outer light source (such as other lamp and sunlight) is I, can be measured by light intensity receptor A.
The above, be only best mode for carrying out the invention, is anyly familiar with those skilled in the art in the technical scope that the present invention discloses, and the simple change of the technical scheme that can obtain apparently or equivalence are replaced and all fallen within the scope of protection of the present invention.