# User talk:Azjps/sandbox

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
User talk:Azjps/sandbox/gov school

1) Note that $311_{10} = 100110111_2$, so $2^{311} = 2^{2^8 + 2^5 + 2^4 + 2^2 + 2^1 + 2^0} = 2^{2^8} \times 2^{2^{5}} \times 2^{2^{4}} \times 2^{2^{2}} \times 2^{2^{1}} \times 2^{2^{0}} \quad (*)$. It requires $0$ multiplications to find $2^0, 2^1$, and by repeatedly squaring, we can find $\left(2^1\right)^2 = 2^2,\quad \left(2^2\right)^2 = 2^{2^2},\quad \left(2^{2^2}\right)^2 = 2^{2^2\times 2} = 2^{2^3}$ and so forth. Each squaring requires one multiplication, and so we can achieve $\left\{2^{2^0}, \ldots, 2^{2^8}\right\}$ using $8$ multiplications. Substituting into $(*)$, we find that our expression requires $5$ more multiplications. Thus, $8+5 = \boxed{13}$ multiplications are sufficient.

2)

$\begin{tabular}{|r||r|r|r|r|r|r|r|r|r|r|} \hline (a,n) & a^0 \mod{n} & a^1 \mod{n} & a^2 \mod{n} & a^3 \mod{n}& \cdots&&&&& a^{10} \mod{n} \\ (3,5) & 1 & 3 & 4 & 2 &&&&&& \\ (2,11) & 1&2&4&8&5&10&9&7&3&6 \\ \hline \end{tabular}$ (Error compiling LaTeX. ! Missing $inserted.) Since each of $\left\{a^{0}, a^{1}, \cdots, a^{n-2}\right\}$ are distinct (and consequently is a permutation of $\{1,2,\ldots,n-1\}$), then both are generators with respect to the given modulos. 3) By the Euclidean Algorithm, $\text{gcd}\,(288,84) = \text{gcd}\,(288 - 3\times 84,84)$ $= \text{gcd}\,(36,84) = \text{gcd}\,(36,84-2\times 36)$ $= \text{gcd}\,(36,12) = \boxed{12}$. 4) Let the number of students be $n$. Then the given conditions yield that$\begin{align*}n &\equiv 11 \pmod{13} \\ n &\equiv 5 \pmod{12} \end{align*}(Error compiling LaTeX. ! Package amsmath Error: \begin{align*} allowed only in paragraph mode.) By trial-and-error, we can easily find that $n \equiv 89 \pmod{156}$ satisfies these conditions, which must be the distinct solution due to the Chinese Remainder Theorem (and since $\text{gcd}\,(12,13)=1$). Since this year we only have $78$ students at Governor's School, we will assume that $\boxed{89}$ is the desired answer, and that we let our counselors pose as students (just kidding). Alternatively, we could note that $12^{-1} \equiv 12 \pmod{13}$ and that $13^{-1} \equiv 1 \pmod{12}$ using the Extended Euclidean Algorithm or by inspection, and thus the answer is $11 \times 12 \times 12 + 5 \times 1 \times 13 \equiv 89 \pmod{156}$. 5) Consider computing $a^m \pmod{n},\ a (this is not really necessary, since we could simply reduce if $a>n$). Assume that it is computationally easy to compute the product of two numbers, both $. Notice then that it is computationally easy to find $a^2$ (which requires just one multiplication, and the numbers are not extremely large as $a). Similarly, it is computationally easy to reduce $a^2 \pmod{n}$. Suppose we express $m = b_kb_{k-1}\cdots b_{1_2}$ in binary form, with $k=\left\lfloor \log_2 m\right\rfloor$ digits (for the given problem, $\left\lfloor \log_2 532452 \right\rfloor = 19$). Then $a^m \equiv a^{2^{b_k} + 2^{b_{k-1}} + \cdots + 2^{b_1}} \equiv a^{2^{b_k}} \times a^{2^{b_{k-1}}} \times \cdots \times a^{2^{b_1}} \pmod{n}$. Each of these terms being multiplied together can be found by squaring $a$, $k$ times (as established above, $k$ is not very large). Additionally, the multiplications are also assumed to be easy from above. Thus, that the exponent yields a huge number does not pose a computational difficulty. 6) The given conditions yield that\begin{align*}n &\equiv 2 \pmod{11} \\ n &\equiv 1 \pmod{13} \\ n &\equiv 3 \pmod{15} \\ n &\equiv 5 \pmod{19} \end{align*}(Error compiling LaTeX. ! Package amsmath Error: \begin{align*} allowed only in paragraph mode.) Using the Chinese Remainder Theorem repeatedly, the answer comes out to be $\boxed{16953} \pmod{11 \times 13 \times 15 \times 19 = 40755}$, which indeed fits the conditions (of course then $16953$ is the desired answer). Work: solving the first two congruences, and then the second two (by trial-and-error), yields\begin{align*}n &\equiv 79 \pmod{143} \\ n &\equiv 138 \pmod{285}\end{align*}(Error compiling LaTeX. ! Package amsmath Error: \begin{align*} allowed only in paragraph mode.) Here we notice that $285$ happens to be $2 \times 143 - 1$, which helps us to quickly determine the inverses: $285^{-1} \equiv -1 \pmod{143}$ and $143^{-1} \equiv 2 \pmod{285}$. Then by the Chinese Remainder Theorem, we have $n \equiv 2 \times 143 \times 138 -1 \times 285 \times 79 \equiv 16953 \pmod{40755}$. 7) For a pseudorandom construction, it would not be desirable for an external observer to predict a bit given the previous bits. However, with the given construction, and since $DES$ is a publically known one-way function, an observer could simply carry out $DES$ on the previously generated bits (let $DES_{n}(s) = \underbrace{DES(DES(\cdots(DES(s))\cdots)}_{n\ \text{times}}$, then given $DES_n(s)$, the outsider can easily carry out $DES(DES_n(s)) = DES_{n+1}(s)$), and determine the next bit him/herself. Note that the observer does not need to know the value of the seed $s$, while in the first construction the observer would still need to know $s$. 8) Let Andy want to send a secret message to Blase, but Blase only has a cell-phone. We assume that the limits imposed by Blase's computational restrictions do not apply to Andy. Then Andy computes two large prime numbers $p,q$, and sends $n = p\times q$ to Blase (if desired, Andy can also send the length of his message, $|M|$, to Blase). Blase then generates a one-time pad, $K$, and sends $K^2 \pmod{n}$ back to Andy (squaring is computationally easy). Now Andy can use the Rabin decryption algorithm to find the value of $K$. Let the binary operation $XOR(a,b)$ be denoted as $a \oplus b$. We note some basic properties of $XOR:$ $a \oplus b = b \oplus a$ (commutative), $a \oplus (b \oplus c) = (a \oplus b) \oplus c$ (associative), $a \oplus 0 = a$, $a \oplus a = 0$. Since it is assumed that an outside attacker could not determine the value of $K$ (performing the Rabin decryption without knowing $p,q$ being a difficult problem), Andy now sends $M \oplus K$ back to Blase. By the given, this is also cryptographically secure. To find the message, Blase performs $(M \oplus K) \oplus K = M \oplus (K \oplus K) = M$, as desired. 9) We programmed on Excel because MATLAB was unable to handle the huge exponents. Using $a = 3,5,7$ for simplicity of calculations, we find that\begin{tabular}{|r||r|r|r||r|}

\hline n & 3^{n-1} \pmod{n} & 5^{n-1} \pmod{n} & 7^{n-1} \pmod{n} & \text{Prime\ or\ Composite?} \\ \hline 6173 & 1 & 1 & 1 & P \\ 6179 & & & 4547 & C \\ 8415* & & & & C \\ 4113* & & & & C \\ 4691 & 1 & 1 & 1 & P \\ 5109* & & & & C \\ 7543 & 4466 & & & C \\ 7907 & 1 & 1 & 1 & P \\ \hline

\end{tabular}$(Error compiling LaTeX. ! Missing$ inserted.)

The numbers with asterisks are either trivially divisible by $3$ or $5$. For the numbers that are denoted with $P$, we can be reasonably sure that they are primes, which they indeed turn out to be. However, we cannot be completely sure that they are prime, due to our lack of randomness in choice of bases for the exponents, and because we only carried out a small number of tests.

10) Note that Caleb does not actually need to know Blase's bid $x$, as Caleb only needs to send $E(2x)$. By the statements of RSA, we know that Blase sent $E(x) \equiv x^e \pmod{n}$, where $e,n, E(x)$ are public. Caleb then wants to send $E(2x) \equiv (2x)^e \equiv 2^ex^e \equiv \boxed{2^eE(x) \pmod{n}}$. It is computationally easy for Caleb to perform this exponentiation (just as it was for Blase) and multiplication, and he has sufficient information.

11) $47^{1395} \equiv (-1)^{1395} \equiv -1 \equiv \boxed{47} \pmod{48}$, as $1395$ is odd.

12) $4^{3207} \equiv 4^{5} \times 4^{3202} \equiv 1024 \times 4^{3202} \equiv 0 \times 4^{3202} \equiv \boxed{0} \pmod{1024}$.

13) The following code can factor the product of two primes (MATLAB's factoring function only works for numbers $< 2^{32}$, so we scaled down all of the requested answers by $2\times$)

p = input('Enter prime 1: ')
q = input('Enter prime 2: ')
tic
factor(p * q)
toc

$\begin{tabular}{|r||r|r|r|} \hline \text{bits} & p & q & \text{time} \\ \hline 2 & 3 & 2 & 0.013334 \\ 4 & 11 & 13 & 0.013267 \\ 8 & 129 & 227 & 0.013529 \\ 10 & 803 & 937 & 0.012896 \\ 12 & 3203 & 3701 & 0.012944 \\ 16 & 33893 &47339 & 0.016408 \\ \hline \end{tabular}$

There is not a very strong correlation between the size of the primes because the used numbers are not particularily large. However, the quickest factoring algorithms (elliptic curve, quadratic sieve, and general number field sieve), run in sub-exponential time when it attempts to factor huge numbers.

14) $\left(x^{-1}\right)x \equiv 1 \pmod{n}$ can be rewritten as $\left(x^{-1}\right)x + kn = 1 \quad (*)$ for some integer $k$. We know that there are solutions to $ax + by = c$ if $c = \text{gcd}\,(a,b)$, which indeed is the case here as $\text{gcd}\,(41,167) = 1$. Thus $x^{-1}$ exists.

To find it, we perform the Extended Euclidean Algorithm on $(*)$:

\begin{align*} 167 &= 4\times 41 + 3 \\ 41 &= 13 \times 3 + 2 \\ 3 &= 2\times 1 + 1 \\ \\ \Longrightarrow 1 &= 3 - 1\times 2 \\ &= 3 - 1 \times (41 - 13 \times 3) \\ &= (14) \times 3 + (-1) \times 41 \\ &= (14)(167-4\times 41) + (-1) \times 41 \\ &= 14 \times 167 - 57 \times 41 \end{align*} (Error compiling LaTeX. ! Package amsmath Error: \begin{align*} allowed only in paragraph mode.)

Thus $x^{-1} \equiv -57 \equiv \boxed{110} \pmod{167}$.

15) For RSA, one step involves computing $d$ such that $d \times e \equiv 1 \pmod{\phi(n)}$. The existence of such $d \equiv e^{-1}$, from the previous question, requires that $1 = \text{gcd}\,(\phi(n),e) = \text{gcd}\,((p-1)(q-1),e) = \text{gcd}\, (10 \times 12, 8) = 8$. This is a contradiction, and thus $d$ does not exist.