Skip to content

Instantly share code, notes, and snippets.

View nazt's full-sized avatar

Nat nazt

  • Chiang Mai Maker Club
  • Chiang Mai
  • X @nazt
View GitHub Profile
<?
// generate a 1024 bit rsa private key, returns a php resource, save to file
$privateKey = openssl_pkey_new(array(
'private_key_bits' => 1024,
'private_key_type' => OPENSSL_KEYTYPE_RSA,
));
openssl_pkey_export_to_file($privateKey, './keys/privatekey', $passphrase);
// get the public key $keyDetails['key'] from the private key;
<?
$message="Test Message";
//encrypt using publickey
$pubKey = openssl_pkey_get_public(file_get_contents('./keys/public'));
openssl_public_encrypt($message, $encryptedData, $pubKey);
//decrypt using privatekey
$privateKey = openssl_pkey_get_private(file_get_contents('./keys/private'));
openssl_private_decrypt($encryptedData, $decryptedData, $privateKey);
echo "Message : " . $message ."\n<br>\n";
echo "Encrypted : " . $encryptedData ."\n<br>\n";
_grailsscripts() {
SCRIPT_DIRS="$GRAILS_HOME/scripts ./scripts ~/.grails/scripts"
if [ -d plugins ]
then for PLUGIN_DIR in $(ls -d plugins/*/scripts 2> /dev/null); do
SCRIPT_DIRS="$SCRIPT_DIRS $PLUGIN_DIR"
done
fi
for D in $SCRIPT_DIRS; do
if [ -d $D ]
def dash={ symbol , num -> symbol*num}
list= (1..20).toList()
5.times {
Collections.shuffle(list)
println list
}
println dash('-',35)
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
# Decrypt the given cyphertext using the Caesar cipher. Shift by the given
# shift value.
def encrypt(string, shift):
# for i in range('A', 'Z'):
for c in string:
print chr((((ord(c)-ord('a'))+shift)%26)+ord('a')),
def decrypt(ciphertext,shift):
########## BEGIN DESCRIPTION ############################################
##
## Caeser Cipher Decryption.
## Write a function named decrytpion which accepts an encrypted English
## phrase - ciphertext - (parameter 1) and a shift value (parameter 2)
## and decrypts the phrase into plaintext.
##
## *See tests for examples of input and expected output*
##
########## END DESCRIPTION ##############################################
import groovyx.net.http.RESTClient
import groovy.util.slurpersupport.GPathResult
import static groovyx.net.http.ContentType.*
def userName= 'user'
def passwd ='pass'
twitter = new RESTClient( 'https://twitter.com/statuses/' )
twitter.auth.basic userName, passwd
def msg = "I'm using HTTPBuilder's RESTClient on ${new Date()}"
import groovyx.net.http.RESTClient
import groovy.util.slurpersupport.GPathResult
import static groovyx.net.http.ContentType.*
def userName= 'user'
def passwd ='pass'
twitter = new RESTClient( 'https://twitter.com/statuses/' )
twitter.client.params.setBooleanParameter 'http.protocol.expect-continue', false
twitter.auth.basic userName, passwd
def msg = "I'm using HTTPBuilder's RESTClient on ${new Date()}"
class AirportMapping{
static constraints = {
name()
iata(maxSize:3)
state(maxSize:2)
lat()
lng()
}
static mapping = {