not a particular programming question but it will relate as we will soon have to implement a one time pad algorithm but before that we need to understand how the math is done for this encryption,I can't seem to find any resources to help me understand this equation.
below is what is in one of the slides,the consistency equation,we are using this in conjunction with OTP(one time pad)
the equation is never explained,could someone try explain to me what is meant below and how the equation works
or have a link to a tutorial thanks
A cipher defined over (K,M,C)
is a pair of βefficientβ algorithms (E, D) where
E: π¦ β β³β π, D: π¦ β π β β³
s.t. βmβ β³, k β π¦: D( k, E(k, m) ) = m
consistency
equation
here is the question I may be asked in the exam
Prove that the OTP satisfies the consistency equation?
Having encrypted a message with a given key, decrypting it with the same key gives you back the original message.
So you need to prove that your OTP algorithm does this. Prove that with your OTP algorithm, the same key applied to encrypot and then decrypt a message will give you back the original message.
you may want to look at some math sites online. This is written in the language of mathematical proofs, and if you can't read it, you can't answer your question! It should not be too hard to find a site that has the symbols and how to read it. I am a bit rusty on it.. st is such that ... you should have had some of this in your class and book but if you can't read it, proof language is what you need to research.
As a simple example, if your OTP is a series of numbers, and your encryption algorithm operates on the letters a-z and space by assigning each a number:
SPACE = 0
a = 1
b = 2
...
z = 26
and your E is "add the next OTP number, and then apply modulus 27"
and your D is "subtract the next OTP number, and then apply modulus 27"
i.e. given a letter value from 0 to 26, adding some_number and taking the % 27 (i.e. encrypting the letter ) , and then subtracting some_number and taking the % 27 (i.e. decrypting the letter) , will give you back the original letter value.
Hell, as a brutally simple encryption algorithm, if your E is just "add the next number from the OTP" and your D is "subtract the next number from the one time pad" you just need to prove that
@repeater yes that actually makes sense now! we did an example in class without the formula and to encrypt the message then decrypt the message we used something similar but from a-z 0 - 25
and E was add each of the letters corresponding numerical value with the OTP's numerical value,if the value was greater than 26 subtract 26
then D was subtract 26 if value is a negative add 26 or something similar
thanks =)
btw can you recommend any good cipher sites which will give me some OTP challenges
how would you encrypt if the OTP key is longer than the message?
OTP requires the key length to be greater to or equal to the message length. Having a key that's longer than the message itself doesn't help anything, so you might as well just truncate the key. The other option would be to add buffer to the end of your message to match the key size.
getNumber and getValue
Please do know you don't need a case for every letter of the alphabet. chars are easily convertible to their corresponding int values, with a shift needed to make 'a' <==> 0.
1 2 3 4 5 6 7 8 9 10 11 12 13
// Example program
#include <iostream>
#include <string>
int getValue(char c)
{
returnstatic_cast<int>(c - 'a');
}
int main()
{
std::cout << getValue('c') << std::endl; // 2
}
xor is your friend. its easy to prove that its self reversing, and its almost always a cpu circuit / instruction of the highest performance, and you can do 8 bytes at a time on a 64 bit computer.