Theory
For the first question, think of prime numbers.
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71
For the second question, think of hex numbers:
Int Hex 0 00 1 01 2 02 3 03 4 04 5 05 6 06 7 07 8 08 9 09 10 0A 11 0B 12 0C 13 0D 14 0E 15 0F
For the third question, think of octal numbers:
Int Oct 0 00 1 01 2 02 3 03 4 04 5 05 6 06 7 07 8 10 9 11 10 12 11 13 12 14 13 15 14 16 15 17
For the fourth question, for a ring in encryption, we create a \(g\) value and have a prime number of \(N\). For values of x, we get \(g^x \pmod N\). For example if we use \(g=2\) and \(N=42\):
1 2 2 4 3 8 4 16 5 32 6 22 7 2 8 4 ... 40 16 41 32 42 22 43 2 44 4
Notice that we repeat after 42, and start the sequence again with 2, 4, etc.
In the 5th challenge, we use a Blum Blum Shub generator. The Blum Blum Shub (BBS) method is as pseudorandom number generator and was created by Lenore Blum, Manuel Blum and Michael Shub in 1968. It uses the form of:
\(x_{n+1}=x_n^2 \pmod M\)
and where \(x_0\) is a random seed. The value of \(M\) is equal to \(p \times q\), and where \(p\) and \(q\) are prime numbers. Let's try a simple example in Python:
>>> p=7 >>> q=11 >>> M=p*q >>> x0=5 >>> x1=(x0**2)%M >>> x2=(x1**2)%M >>> x3=(x2**2)%M >>> x4=(x3**2)%M >>> print (x1,x2,x3,x4) 25 9 4 16
Coding
If you are interested, here is the C# code I have used:
public int getG(int p) { for (int i = 2; i < p; i++) { int rand = i; int exp = 1; int next = rand % p; while (next!=1) { next = (next * rand) % p; exp = exp + 1; } if (exp == p - 1) return (rand); } return (2); } public string ring(ref string ans1) { int[] prime = { 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73 }; int r = getRandom(prime.Length); int myprime = prime[r]; int g=(int)getG(myprime); string rtn = "For a g value of "+g+" and a prime number of "+myprime+", what is the next value in the sequence of "; int val = (int)Math.Pow(g, 1) % myprime; rtn = rtn + val.ToString(); for (int i =2; i < 7; i++) { val =(int)Math.Pow(g,i) % myprime; rtn = rtn + ", " + val.ToString(); } val = (int)Math.Pow(g, 7) % myprime; ans1 = val.ToString(); rtn += ", ..."; return (rtn); } public string seqoct(ref string ans1) { int r = 1 + getRandom(6); int a = 2 + getRandom(6); string rtn = "What is the next value in the sequence of "; rtn = rtn + Convert.ToString(r, 8); for (int i = 1; i < 5; i++) { r = r + a; rtn = rtn + ", " + Convert.ToString(r, 8); int b = r + a; ans1 = Convert.ToString(b, 8); } rtn += ", ..."; return (rtn); } public string seqhex(ref string ans1) { int r = 1+getRandom(5); int a = 1+getRandom(6); string rtn = "What is the next value in the sequence of "; rtn=rtn+r.ToString("X2").Replace("0x",""); for (int i = 1; i < 5; i++) { r = r + a; rtn = rtn + ", " + r.ToString("X2").Replace("0x", ""); int b = r + a; ans1=b.ToString("X2").Replace("0x", ""); } rtn += ", ..."; return (rtn); } public string seqprime(ref string ans1) { int[] prime = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73 }; int r = getRandom(5); int val = prime[r] * prime[r+1]; string rtn = "What is the next value in the sequence of "+val; for (int i=r+1;i<r+5;i++) { int res = prime[i] * prime[i + 1]; rtn = rtn + ", " + res; ans1 = "" + (prime[i+1] * prime[i + 2]); } rtn += ", ..."; return (rtn); } public string blum(ref string ans1) { int[] prime = { 19, 23, 31, 43, 47, 59, 67, 71}; int r = getRandom(prime.Length); int p = prime[r]; r = getRandom(prime.Length); int q = prime[r]; int N = p * q; int x0= 2+getRandom(prime.Length); string rtn = "For prime numbers of " + p+" and " + q+ " and a seed of x0=" +x0 + ", what is the next value in the sequence of "; int x1 = (int)Math.Pow(x0, 2) % N; int x2 = (int)Math.Pow(x1, 2) % N; int x3 = (int)Math.Pow(x2, 2) % N; int x4 = (int)Math.Pow(x3, 2) % N; int x5 = (int)Math.Pow(x4, 2) % N; rtn += x1 + ", " + x2 + ", " + x3 + ", " + x4 + ", ..."; ans1 =x5.ToString(); return (rtn); }