Skip to content

Instantly share code, notes, and snippets.

@mba7
mba7 / crypto-pbkdf2-promise-example.js
Last active October 12, 2020 14:39 — forked from skeggse/crypto-pbkdf2-example.js
Example of using crypto.pbkdf2 to hash and verify passwords asynchronously using bluebird promise, while storing the hash and salt in a single combined buffer along with the original hash settings
var Promise = require('bluebird');
var crypto = Promise.promisifyAll(require("crypto"));
// http://security.stackexchange.com/questions/110084/parameters-for-pbkdf2-for-password-hashing
var config = {
hashBytes : 64, // size of the generated hash (to be chosen accordint the the chosen algo)
saltBytes : 16, // sise of the salt : larger salt means hashed passwords are more resistant to rainbow table
iterations : 500000, // tune so that hashing the password takes about 1 second
algo :'sha512',
encoding : 'base64' // hex is readable but base64 is shorter
@mba7
mba7 / enumerate_serial_ports.py
Created June 18, 2014 14:20
enumerate the availables serial ports using pyserial
def enumerate_serial_ports():
"""
Purpose: scan for available ports
Return: return a list containing the names of
the availables serial ports
"""
outAvailablePorts = []
for i in range(256):
try:
s = serial.Serial(i)
@mba7
mba7 / crc16.py
Last active August 29, 2015 14:02
crc16 computer
################# Compute CRC16 from buffer ###############
""" usage: add : from crc16 import crc16
call crc16(vCRCList)
"""
def crc16(packet):
POLY = 0x8408 # 0x8408 is deduced from the polynomial X**16 + X**12 + X**5 + X**0
# process each byte
vFCS = 0xFFFF; # init FCS to all ones
@mba7
mba7 / ser_sender.py
Created June 17, 2014 09:09
Simple Serial Port Sender
import serial
import random, time, math
ser = serial.Serial(0, 38400)
incycle = 0
while True:
t = int(random.randint(60, 80) * (1 + math.sin(incycle)))
print "sent data:", t