Skip to content

Instantly share code, notes, and snippets.

View wqweto's full-sized avatar

Vladimir Vissoultchev wqweto

View GitHub Profile
@PedroAlvesV
PedroAlvesV / sha2for51.lua
Created August 31, 2018 18:29
working implementation of SHA512 for Lua 5.1
-- This module contains functions to calculate SHA2 digest.
-- Supported hashes: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256
-- This is a pure-Lua module, compatible with Lua 5.1
-- It works on Lua 5.1/5.2/5.3/5.4/LuaJIT, but it doesn't use benefits of Lua versions 5.2+
-- Input data may must be provided either as a whole string or as a sequence of substrings (chunk-by-chunk).
-- Result (SHA2 digest) is a string of lowercase hex digits.
--
-- Simplest usage example:
-- local your_hash = require("sha2for51").sha512("your string")
#define SECURITY_WIN32
#include <iostream>
#include <tuple>
#include <Windows.h>
#include <security.h>
#include <schannel.h>
#pragma comment(lib, "Secur32.lib")
static std::tuple<int, const char*> protocols[] = {
{ SP_PROT_PCT1_CLIENT, "PCT 1.0" },
@hasherezade
hasherezade / aes_crypt.cpp
Last active August 6, 2024 15:31
AES 128 - encrypt/decrypt using Windows Crypto API
#include <Windows.h>
#include <wincrypt.h>
#include <stdio.h>
#pragma comment(lib, "advapi32.lib")
#define AES_KEY_SIZE 16
#define IN_CHUNK_SIZE (AES_KEY_SIZE * 10) // a buffer must be a multiple of the key size
#define OUT_CHUNK_SIZE (IN_CHUNK_SIZE * 2) // an output buffer (for encryption) must be twice as big
//params: <input file> <output file> <is decrypt mode> <key>
@randrews
randrews / hoc4.lua
Created June 21, 2015 20:53
Toy calculator in Lua, version 4
setmetatable(_ENV, { __index=lpeg })
Scopes = { {} }
function eval_expr(expr)
local accum = eval(expr[2]) -- because 1 is "expr"
for i = 3, #expr, 2 do
local operator = expr[i]
local num2 = eval(expr[i+1])
@sharwell
sharwell / CaseInsensitiveInputStream.java
Created March 8, 2014 03:00
Case insensitive input stream for ANTLR 4
/*
* [The "BSD license"]
* Copyright (c) 2012 Terence Parr
* Copyright (c) 2012 Sam Harwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
@sharwell
sharwell / CaseInsensitiveStringStream.cs
Created February 19, 2014 05:10
Case-insensitive ANTLRStringStream for ANTLR 3
using Antlr.Runtime;
public class CaseInsensitiveStringStream : ANTLRStringStream
{
// the string used for lookahead (performance improvement by not having to call Char.ToLowerInvariant())
private readonly string _lastring;
public CaseInsensitiveStringStream(string input, string sourceName)
: base(input, sourceName)
{
@armornick
armornick / parser.lua
Last active December 21, 2015 15:58
Kaleidoscope parser made with LPeg
-- debug helper function
function _dump (t)
local ttype = type(t)
if ttype == "table" then
local vals = {}
for k,v in pairs(t) do
table.insert(vals, _dump(k) .. " = " .. _dump(v))
end
return "{"..table.concat(vals, " , ").."}"
elseif ttype == "string" then
@mindplay-dk
mindplay-dk / StringSubstitutionExtension.cs
Created March 31, 2011 16:39
A static class that allows you to use name/value pairs from an dictionary to substitute string-representations of object values - this extension complements String.Format()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Mindplay.Extensions
{
/// <summary>
/// This extension provides an alternative to <see cref="String.Format"/> allowing the
/// use of an <see cref="IDictionary{String,Object}"/> to replace named (rather than