Skip to content

Instantly share code, notes, and snippets.

@ErbaAitbayev
ErbaAitbayev / rsa.py
Created October 5, 2016 08:28
Simple Python RSA for digital signature with hashing implementation. For hashing SHA-256 from hashlib library is used.
import random
from hashlib import sha256
def coprime(a, b):
while b != 0:
a, b = b, a % b
return a
@ErbaAitbayev
ErbaAitbayev / knn.py
Last active October 24, 2016 08:58
Python KNN (k-nearest neighbors) implementation with graphical representation (using matplotlib) of dependency between K and accuracy rate. Different K values tested (from 1 to 25). For each K 100 accuracy rates recorded and plotted.
import csv
import random
import math
import operator
from time import time
def loadDataset(filename, divFactor, trainData=[] , testData=[]):
with open(filename, 'r') as csvfile:
lines = csv.reader(csvfile)
dataset = list(lines)