Skip to content

Instantly share code, notes, and snippets.

View Sajjon's full-sized avatar
💭
FOSS|Rust&Swift|Principal Cryptography & Middleware Engineer@RDX Works/Radix DLT

Alexander Cyon Sajjon

💭
FOSS|Rust&Swift|Principal Cryptography & Middleware Engineer@RDX Works/Radix DLT
View GitHub Profile
@Sajjon
Sajjon / dynamic_member_lookup_environment.swift
Created January 2, 2019 22:10 — forked from DougGregor/dynamic_member_lookup_environment.swift
Using Swift 4.2's @dynamicMemberLookup to expose environment variables
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
@Sajjon
Sajjon / operatorCharacters.swift
Created September 1, 2018 08:24 — forked from natecook1000/operatorCharacters.swift
Allowed characters for Swift operators
import Foundation
extension UnicodeScalar : ForwardIndexType {
public func successor() -> UnicodeScalar {
return UnicodeScalar(value + 1)
}
}
var operatorHeads: [UnicodeScalar] = Array("=-+!*%<>&|^~?".unicodeScalars)
operatorHeads += Array("\u{00A1}" ... "\u{00A7}")
@Sajjon
Sajjon / Montgomery.py
Created August 4, 2018 13:46 — forked from natmchugh/Montgomery.py
Montgomery Ladder
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
@Sajjon
Sajjon / montgomery_ladder.py
Created August 4, 2018 11:17 — forked from stribika/montgomery_ladder.py
Basic Montgomery ladder implementation. In the test it works with just numbers, but you can plug in any operation.
#!/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
@Sajjon
Sajjon / curve.md
Created August 4, 2018 10:04 — forked from merryhime/curve.md

Merry's very quick guide to elliptic curve crypto

An elliptic curve is made up of the following:

  1. 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.
  1. An equation and it's parameters:
@Sajjon
Sajjon / hack.sh
Created May 18, 2017 12:25 — forked from erikh/hack.sh
OSX For Hackers
#!/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
#