## 2019年3月22日金曜日

### Python - Finite Fields - Finite Field Multiplication and Exponentiation - modulo

Programming Bitcoin: Learn How to Program Bitcoin from Scratch (Jimmy Song(著)、O'Reilly Media)のChapter 1(Finite Fields)、Finite Field Multiplication and Exponentiation、Exercises 4、5(11)の解答を求めてみる。

コード

Python 3

```#!/usr/bin/env python3

print('4.')
for n in [95 * 45 * 31, 17 * 13 * 19 * 44, 12 ** 7 * 77 ** 49]:
print(n % 97)

print('5.')
for k in [1, 3, 7, 13, 18]:
print(f'k = {k}')
print({k * n % 19 for n in range(19)})
print([k * n % 19 for n in range(19)])
```

```C:\Users\...>py -3 sample4.py -v
4.
23
68
63
5.
k = 1
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
k = 3
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}
[0, 3, 6, 9, 12, 15, 18, 2, 5, 8, 11, 14, 17, 1, 4, 7, 10, 13, 16]
k = 7
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}
[0, 7, 14, 2, 9, 16, 4, 11, 18, 6, 13, 1, 8, 15, 3, 10, 17, 5, 12]
k = 13
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}
[0, 13, 7, 1, 14, 8, 2, 15, 9, 3, 16, 10, 4, 17, 11, 5, 18, 12, 6]
k = 18
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}
[0, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

C:\Users\...>
```