miércoles, 29 de agosto de 2012

Statistical test homework

Statistical test

Hi, in this homework i made a statistical test to my keys generated in the past homework, this is the link to my past homework (http://triana-integrador-cripto.blogspot.mx/2012/08/one-time-pad.html).

Ok, this is an example of 10 keys generated in mi program.

A numeric sequence is said to be statistically random when it contains no recognizable patterns or regularities.

Any method to generate random numbers must satisfy next conditions:

- Uniformly distributed
- Without constant repetition in a specified length (often not repeatable)
- Numbers must be independent of each other
- The series should be reproducible
- Numbers must be generated quickly
Well, there are many ways or methods to determine if a sequence of number are random.
I will use the method called: Media Test (Prueba de medias)

Media Test

Ok, media test method consists in verify that generated numbers have a statics media between upper and lower limits.

The 3 important elements to work with media test are the next:

* R = Is the summation of all numbers in the test, multiplied by (1/ total of numbers)
This number will be compared whit  the lower and upper limits. If the R value is in the range of the limits, the numbers are random, if R is out of range with the limits, the numbers are not random.
R is calculated:



* Lower limit = Is the lowest limit to compare with the "r"
Lower limit is calculated:

Za = Z value of alfa (not acceptance level). You must use the normal distribution table
* Upper limit = Is the highest limit to compare with the "r"
Upper limit is calculated:

We are going to set an alfa, alfa value is the number of error probabilities. Assuming we want a 95 percent of acceptance level, alfa will be 5 percent of not acceptance, so alfa = 0.05.

I'll create the keys like in the one time pad homework, like this:

Then i created a code to count all 0 and 1 in the text file, and the total of numbers.
zAlfa = 0.5199, because alfa = 0.05, here is the table were i got "z" value: http://www.tuveras.com/estadistica/normal/tabla.htm

And finally with all the number added, i calculated the value of "r". And too calculated the values of lower and upper limits.

Like this:

This is the entire code (if you want to copy it):

These are some screen shots of my program running: 


Generated keys                                                                              Results


If you have any doubt you can leave it in comments. 
Sorry for my bad english. Thank you! 

martes, 28 de agosto de 2012

One time pad

One Time Pad

Hi everyone, this is the homework of one time pad. Firstly one time pad is a concept  of cryptography, is a type of encryption algorithms by which the plain text is combined with a random key same length as the plain text and used only once. It was invented in 1917. If the key is truly random, never reused and, of course, is kept secret, it can be shown that the method of the one-time pad is unbreakable. 

So, for this homework i created a one time pad encryption using Python, i'll resume all my work in few steps. 

1 - I created the text files ("keys1.txt", and "keys2.txt")

These are all the keys generated(in both files: "keys1.txt", and "keys2.txt"). 10 different keys, but it doesn't matter because each message crypted and decrypted will generate different keys. The length of each key is 7  because this is the length of ASCII values (in binary).

2 - I requested to user for a string 

3 - Each character of the string gave by the user goes to the encrypt function.

4 - Then each character goes to the decrypt function

5 - Finally i printed out the binary value of the character, key used,  xor result, xor decrypted (using xor method again), ASCII value and the character decrypted.

Now, this is all my code...

Finally this is mi program running (The message is: its)

If you want to write more messages you must to type 1 (if you type 2, program will close), and new messages will be crypted with other new key.

Leave your comment if you have any doubt

Thank you