Laborator Nr.1

Embed Size (px)

DESCRIPTION

Laborator Nr.1

Citation preview

Universitatea de Stat din MoldovaFacultatea de Fizic i InginerieCatedra de Fizic Aplicat i Informatic

Securitatea TranzaciilorLucrare Individual Nr.1Tema: Exponentiere Modular

Student: Bostanica Ion Lect .sup.: Cerbu O,

Chiinu 2015Scopul lucrrii: Analiza procesului de exponentiere modular i elaborarea unui program care ar permite efectuarea operatiei date:

Algoritmul:

Exemplul practic:6589 8953 mod 2875 = 2344c = 8953x = 6589n = 2875

(8953)10 = (10001011111001)2iciz

131z= z2 mod n = 12 mod 2875=1 * 6589 mod 2875 = 839

1208392 mod 2875 = 2421

11024212 mod 2875 = 1991

10019912 mod 2875 = 2331

9123312 mod 2875 = 2686 * 6589 mod 2875 = 2429

8024292 mod 2875 = 541

715412 mod 2875 = 2306 * 6589 mod 2875 = 2734

6127342 mod 2875 = 2631 * 6589 mod 2875 = 2284

5122842 mod 2875 = 1406 * 6589 mod 2875 = 884

418842 mod 2875 = 2331 * 6589 mod 2875 = 709

317092 mod 2875 = 2431 * 6589 mod 2875 = 1234

2012342 mod 2875 = 1881

1018812 mod 2875 = 1911

0119112 mod 2875 = 671 * 6589 mod 2875 = 2344

Cod Surs:package def;

import static def.Utils.getBit;import static def.Utils.getNumBits;import static def.Utils.println;import static def.Utils.readLong;

public class ModularExponentiation {

public static void main(String[] args) {

println("Introduceti C:");long c = readLong();println("Introduceti X:");long x = readLong();println("Introduceti N:");long n = readLong();

println("Z = " + apply(c, x, n));}

public static long apply(long c, long x, long n) {long z = 1;int s = getNumBits(c);

for (int i = (s - 1); i > -1; i--) {int ci = getBit(c, i);z = (ci == 1) ? (z * x) % n : (z * z) % n;}

return z;}}

Execuia: