Skip to content

Instantly share code, notes, and snippets.

@artjomb
artjomb / CryptoJS_byteArrayWordArrayConversions.js
Last active January 9, 2024 16:43
Convert a byte array to a word array and back in CryptoJS-compatible fashion
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 June 13, 2016 09:16
Testing the double click capability of PhantomJS
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 June 4, 2016 14:23
ECMAScript 6 capability of PhantomJS 2.1.1
// 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 March 26, 2024 06:14
List of Pairing Libraries

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.

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 April 5, 2022 22:10
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.
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 + '")');
};
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 {
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 June 12, 2023 00:00
infinite scroll of stackstatus with python in phantomjs
import selenium
import time
from selenium import webdriver
browser = webdriver.PhantomJS("phantomjs")
browser.get("https://twitter.com/StackStatus")
print browser.title
pause = 3
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',
@artjomb
artjomb / gist:a84e915f05b03cf19bdc
Created November 25, 2014 14:00
nightmareDownload.js
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) {