13
2
This is a simple encryption method that uses PI digits to encode a message, the method is simple:
The key is just a positive integer that indicates where the window starts then:
Given a string to encrypt, containing only lowercase letters, no spaces, you take its length, then you find the Nth digit of PI and then proceeds to shift every letter to the right for the amount indicated by the digit.
For example, if the key is 2
and I want to encode house
, I take a window of 5 digits from the second one: 14159
and then it becomes:
h -> i
o -> s
u -> v
s -> x
e -> n
a.- Your program/function/algorithm will receive two parameters, an string composed only of lowercase letters with no spaces and the key, which will be just a positive integer between 1 (1 refers to 3) and 1000, which could be more or less as I'm not quite sure how long does it take to compute PI with said accuracy because:
b.- You must compute PI yourself in your code, here is a neat webpage to compare with: Pi Day. The input should never have you calculate PI beyond the 1000 digit, meaning that length(message)+key <= 1000.
By computing Pi, I mean not harcode it in your code (silly for a code golf) nor use any embedded constant in your code nor any trigonometric identity (2*acos(0)) nor any web reference.
c.- The output will be just the encrypted string.
This is a code golf question, shorter code wins!
I'll be accepting the winning answer at July 14th, 2014.
1What happens when letters are shifted past the end of the alphabet? Does wrap-around to the beginning of the alphabet occur or something else? – Digital Trauma – 2014-06-27T22:39:23.100
1Yes, you just start over from the beginning. – BrunoJ – 2014-06-27T22:51:22.960
6What counts as "compute yourself"?
ArcCos(-1)
? – Martin Ender – 2014-06-28T00:04:28.060Please read this question and its comments very carefully. Then please edit your question to specify what you mean by "compute PI yourself"
– Digital Trauma – 2014-06-28T00:30:25.293Is
3
the zeroth or the first digit of pi? – Digital Trauma – 2014-06-28T00:32:49.1331I explained better what I wanted to say by computing it yourself and pointed that 3 is the first digit. – BrunoJ – 2014-06-28T01:09:04.577
Key
1
and the the stringaaaaa
will givedbebf
witha
=0
,b
=1
, etc. By replacing the letters by the numbers, we can compute Pi by using the answers to this question. :-) – A.L – 2014-06-28T03:06:28.087This is effectively two challenges whose scores you sum: computing digits of pi and doing Caesar shifts by a series of offsets. The first has been done, so I'd suggest just doing the second, perhaps by allowing the embedded constant pi. There has been a similar letter-shifting question though: http://codegolf.stackexchange.com/questions/678/decipher-a-vigen%C3%A8re-ciphertext
– xnor – 2014-06-28T03:21:10.9871This actually seems like a really smart encryption algorithm, why isn't this widely used (except with a more complicated constant like e^pi or something less recognizable)? – ASKASK – 2014-06-28T22:55:18.780
@ASKASK you'd need trillions or maybe more digits of Pi to protect against brute forcing/dictionary attacks – Digital Trauma – 2014-06-29T01:30:29.553
Does the pi calculation need to have a reasonable runtime? Any bound on how many digits we might need to compute? – xnor – 2014-06-29T03:41:44.597
@DigitalTrauma Here is what I'm thinking: Along with the encoded message there is some sort of numerical key (maybe the date or something like that) which is passed into a function (ex: f(x)=e^(pi*x)) which generates a number of infinite digits that appear in no obvious order. The attacker would need to know the exact function to generate the number in order to know the pattern at which the letters were being shifted. How could a brute force/dictionary figure that out? – ASKASK – 2014-06-29T06:23:47.837
Any limit on the string length? – Aurel Bílý – 2014-06-30T12:30:11.363
Just addressed the string length more clearly and, as answers are already posted I don't think it's wise to split it into two challenges. – BrunoJ – 2014-06-30T15:07:15.473