An elliptic curve is made up of the following:
- A field, F_p.
- What this means is all arithmetic on scalars is modulo p.
- Modern ECC have p as some large prime.
- For curve25519, p = 2^255 - 19, a prime.
- An equation and it's parameters:
import Darwin | |
@dynamicMemberLookup | |
struct Environment { | |
subscript(dynamicMember name: String) -> String? { | |
get { | |
guard let value = getenv(name) else { return nil } | |
return String(validatingUTF8: value) | |
} |
/// Returns a binary predicate using the given key path to create an ascending order | |
/// for elements of type `Root`. | |
func ascending<Root, Value: Comparable>(_ path: KeyPath<Root, Value>) -> (Root, Root) -> Bool { | |
return { $0[keyPath: path] < $1[keyPath: path] } | |
} | |
/// Returns a binary predicate using the given key path to create a descending order | |
/// for elements of type `Root`. | |
func descending<Root, Value: Comparable>(_ path: KeyPath<Root, Value>) -> (Root, Root) -> Bool { | |
return { $0[keyPath: path] > $1[keyPath: path] } |
/// A dictionary wrapper that uses a `CaseIterable` type as its key. | |
/// This differs from a dictionary in two ways: | |
/// | |
/// - Key-value pairs are accessed in a fixed order, which is the same | |
/// as the `Key`'s `allCases` property. | |
/// - Every possible key must have a value given, so using the key-based | |
/// subscript returns a non-optional value. | |
struct CaseMap<Key: CaseIterable & Hashable, Value> : Collection { | |
typealias Index = Key.AllCases.Index |
import Foundation | |
extension UnicodeScalar : ForwardIndexType { | |
public func successor() -> UnicodeScalar { | |
return UnicodeScalar(value + 1) | |
} | |
} | |
var operatorHeads: [UnicodeScalar] = Array("=-+!*%<>&|^~?".unicodeScalars) | |
operatorHeads += Array("\u{00A1}" ... "\u{00A7}") |
import random | |
class Montgomery: | |
# B*v^2 = u^3 + A*u^2 + u | |
def __init__(self, A, B, p): | |
self.A = A | |
self.B = B | |
self.p = p |
#!/usr/bin/python3 -O | |
from math import floor, log | |
def montgomery_ladder(x, n, op, select): | |
k = floor(log(n, 2)) + 1 | |
x1 = x | |
x2 = op(x, x) | |
for i in range(k - 2, -1, -1): | |
bit = 1 if n & (1 << i) else 0 |
#!/usr/bin/env sh | |
## | |
# This is script with usefull tips taken from: | |
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx | |
# | |
# install it: | |
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh | |
# |