One time Pad 
One-time pad
                (OTP), also called Vernam-cipher or the perfect
                cipher, is a crypto algorithm where plaintext is
                combined with a random key. It is the only known
                method to perform mathematically unbreakable
                encryption. Used by Special Operations teams and
                resistance groups in WW2, popular with
                intelligence agencies and their spies during the
                Cold War and beyond, protecting diplomatic and
                military communications around the world for many
                decades, the one-time pad gained a reputation as
                a simple yet solid encryption system with an
                absolute security which is unmatched by today's
                modern crypto algorithms. Whatever technological
                progress may come in the future, one-time pad
                encryption is, and will remain, the only system
                to provide real long-term message security.
One-Time-Pad-(xor)
We can only talk about one-time pad if
                some important rules are followed. If these rules
                are applied correctly, the one-time pad can be
                proven unbreakable (see Claude Shannon's
                "Communication Theory of Secrecy
                Systems"). Even infinite computational power
                and infinite time cannot break one-time pad
                encryption, simply because it is mathematically
                impossible. However, if only one of these rules
                is disregarded, the cipher is no longer
                unbreakable.
- The key is at least as long as the message or data that must be encrypted.
- The key is truly random (not generated by a simple computer function or such)
- Key and plaintext are calculated modulo 10 (digits), modulo 26 (letters) or modulo 2 (binary)
- Each key is used only once, and both sender and receiver must destroy their key after use.
- There should only be two copies of the key: one for the sender and one for the receiver (some exceptions exist for multiple receivers.
Code:
To start the program asks the number of keys that we will generate randomly, in my case is 2.
The Pograma generates two keys and saves them in a file and copy this file, when you do the copy deletes the original key.
Copies were created by users, print the message we send to encrypt.
Bob sends the encrypted message to Ana.
eliminates the key used
Ana receives and decrypts the message, the key used is the same.
Repeat the above using all the keys, and ends when all keys are deleted.
Image where the program ends
empty files







 
Sería mejor tomar el largo y la cantidad de claves como parámetros. Y poner comentarios en el código. La ortografía ocupa mejora y no entiendo la aportación de la imagen al final de la entrada... Van 3 pts.
ResponderEliminar