Skip to content

Instantly share code, notes, and snippets.

@artjomb
artjomb / CryptoJS_byteArrayWordArrayConversions.js
Last active Feb 16, 2021
Convert a byte array to a word array and back in CryptoJS-compatible fashion
View CryptoJS_byteArrayWordArrayConversions.js
function byteArrayToWordArray(ba) {
var wa = [],
i;
for (i = 0; i < ba.length; i++) {
wa[(i / 4) | 0] |= ba[i] << (24 - 8 * i);
}
return CryptoJS.lib.WordArray.create(wa, ba.length);
}
@artjomb
artjomb / test_dblclick.js
Created Jun 13, 2016
Testing the double click capability of PhantomJS
View test_dblclick.js
var f = require('fs');
var page = require('webpage').create();
// http://phantomjs.org/api/webpage/handler/on-console-message.html
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
// http://phantomjs.org/api/webpage/handler/on-error.html
@artjomb
artjomb / create.js
Created Jun 4, 2016
ECMAScript 6 capability of PhantomJS 2.1.1
View create.js
// PhantomJS script for creating this data
var page = require('webpage').create();
var fs = require('fs');
var url = "https://kangax.github.io/compat-table/es6/";
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE> ' + msg);
};
@artjomb
artjomb / PairingLibs.md
Last active Feb 4, 2021
List of Pairing Libraries
View PairingLibs.md

Pairings can be used for all kinds of advanced cryptographic schemes such as Encryption (Identity-based, Attribute-based, Predicate-based, etc.), Signatures, Zero-Knowledge Proofs, etc. It is in no particular order.

PBC

Provides multiple types of Elliptic Curve groups with appropriate pairings on top of them. Code repository resides here.

License: LGPL
Language: C
Thesis: On the Implementation of Pairing-Based Cryptography by Ben Lynn (2007)

@artjomb
artjomb / 1_phantomErrors.js
Last active Jan 25, 2020
Error event handlers for PhantomJS and CasperJS: PhantomJS and CasperJS don't show errors on the page by default. This can give clues as to what did go wrong.
View 1_phantomErrors.js
var page = require('webpage').create(),
url = 'http://example.com/';
// Put the event handlers somewhere in the code before the action of
// interest (opening the page in question or clicking something)
// http://phantomjs.org/api/webpage/handler/on-console-message.html
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
View Test19EncDec.java
package mytest;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;
import org.apache.commons.codec.binary.Base64;
public class Test19EncDec {
View gist:5e6f12b525789d81856c
var casper = require('casper').create();
casper.start("http://stackoverflow.com/contact", function(){
this.capture("test37_1.png"); // ""
this.sendKeys("#search > input", "abcd", {keepFocus: true});
this.capture("test37_2.png"); // "abcd"
this.page.sendEvent("keypress", casper.page.event.key.Left);
this.page.sendEvent("keypress", casper.page.event.key.Left);
this.sendKeys("#search > input", "12");
this.capture("test37_3.png"); // "ab12cd"
@artjomb
artjomb / infiniteScroll_1.py
Last active Jul 11, 2019
infinite scroll of stackstatus with python in phantomjs
View infiniteScroll_1.py
import selenium
import time
from selenium import webdriver
browser = webdriver.PhantomJS("phantomjs")
browser.get("https://twitter.com/StackStatus")
print browser.title
pause = 3
View asyncNonDeprecated.js
var page = require('webpage').create();
var url = 'http://api.jquery.com/jQuery.ajax/';
page.open(url, function (status) {
var result = page.evaluate(function(url){
var result = "blah";
$.ajax({
async: false,
url: "/",
type: 'get',
View gist:a84e915f05b03cf19bdc
var useOldDownloadWay = false;
var Nightmare = require('nightmare');
new Nightmare()
.goto('http://eprint.iacr.org/2004/152')
.evaluate(function ev(old){
var el = document.querySelector("[href*='.pdf']");
var xhr = new XMLHttpRequest();
xhr.open("GET", el.href, false);
if (old) {