PI window encryption 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 -&gt; i
o -&gt; s
u -&gt; v
s -&gt; x
e -&gt; 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 &lt;= 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.
Python - 370

Ok, nice one, finally got the pi thing working with thanks to link1 and link2.

from decimal import *
def f(s,n): 
 j=len(s)
 getcontext().prec=j+n+5
 d=Decimal
 e=d(0)
 for k in range(0,j+n+5): 
  e+=(d(16)**(-k)*(d(4)/(8*k+1)-d(2)/(8*k+4)-d(1)/(8*k+5)-d(1)/(8*k+6)))
 c=`e`.split("'")[1].replace('.','')
 t=''
 for i,l in enumerate(s):
  o=ord(l)
  for v in[0,32]:
   if 64+v&lt;o&lt;91+v:
    l=chr(((o-65-v)+int(c[i+n-1]))%26+65+v)
  t+=l   
 print t


Example output:

&gt;&gt;&gt; f('house',2)
isvxn


and another:

Wimt fcy d dnyh uhkvkv qhvadil   



       >>> f('This was a very secret message',1)