Research Article

Portable Implementation of Postquantum Encryption Schemes and Key Exchange Protocols on JavaScript-Enabled Platforms

Algorithm 1

Knuth-Yao algorithm.
Input: , a probability array
Output: Sample value
1 Let , , ;
2  while  true  do
3 uniformly at random;
4;
5for   down to 0 by 1  do
6;
7if    then
8 if    then   uniformly at random;
9else
10 uniformly at random;
11return  ;
12endif
13if    then return  ;
14else
15;
16 uniformly at random;
17;
18;
19continue
20endif
21endif
22endfor
23;
24 endwhile