# Cryptography I Written Problems: There are three steps to follow...

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

/*
* File:   EllipticCurves.c
* Author:
*
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/**
* 2*9 = 18 mod 17 = 1
* @param val 9
* @param p 17
* @return 2
*/
int pow_1(int val, int p) {
int i;
for (i = 1; i < p; i++) {
if ((i * val) % p == 1) {
return i;
}
}
return val;
}

/**
* 5-6 = -1 → -1 + 17 = 16
* @param val -1
* @param p 17
* @return 16
*/
int negative(int val, int p) {
if (val >= 0) {
return val;
}
int tmp = val * (-1);
tmp = tmp % p;
tmp = tmp * (-1);
return tmp + p;
}

/**
* S = (y2 - y1) / (x2 - x1)
* @param x1
* @param y1
* @param x2
* @param y2
* @param p
* @return
*/
int S3(int x1, int y1, int x2, int y2, int p) {
int x = negative(x2 - x1, p);
int y = negative(y2 - y1, p);
return (y * pow_1(x, p)) % p;
}

/**
* Xresult = S^2 - (x1 + x2)
* @param s
* @param x1
* @param x2
* @param p
* @return
*/
int X3(int s, int x1, int x2, int p) {
int tmp = s * s;
int x = (x1 + x2);
if (x >= 0) {
tmp = tmp - x;
}
else {
tmp = tmp - negative(x, p);
}

if (tmp >= 0) {
return tmp % p;
}

return negative(tmp, p);
}

/**
* Yresult = S(x1 - Xresult) - y1
* @param s
* @param x1
* @param x
* @param y1
* @param p
* @return
*/
int Y3(int s, int x1, int x, int y1, int p) {
x = negative(x1 - x, p);
int tmp = s * x - y1;
if (tmp < 0) {
tmp = negative(tmp, p);
}
return tmp % p;
}

/**
* 3g
* @param a
* @param b
* @param p
* @param x1
* @param y1
* @param x2
* @param y2
*/
void G3(int a, int b, int p, int x1, int y1, int x2, int y2) {
int s = S3(x1, y1, x2, y2, p);
int x = X3(s, x1, x2, p);
int y = Y3(s, x1, x, y1, p);

printf("(%d,%d)", x, y);
}

/**
* S = (3x^2 + a) / (2y)
* @param x
* @param a
* @param y
* @param p
* @return
*/
int S2(int x, int a, int y, int p) {
int tmp = 3 * x * x + a;
tmp = negative(tmp, p);
int y_2 = 2 * y;
y_2 = pow_1(y_2, p);

return (tmp * y_2) % p;
}...

By purchasing this solution you'll be able to access the following files:
Solution.c.

\$100.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.