Skip to content

Instantly share code, notes, and snippets.

@omarrodriguez15
omarrodriguez15 / gist:4693a14afdc4389d84c3
Last active December 30, 2015 22:26
Encrypt blocks
//Encrypt blocks message must be divisible by block size if not there is a fix for it in this function but it is commented out for testing
public static Vector<BigInteger> encryptBlockText(String clearText, BigInteger p, BigInteger q, int BlockSize) {
BigInteger c = null;
String Blocks = null;
String block = null;
int payLoad = 0;
Vector<BigInteger> encryptedBlocks = new Vector<BigInteger>();
Vector<BigInteger> publicKey = generatePublicKey(BlockSize,p,q);
// Check if we have a public key
public static Vector<String> decryptBlocksText(Vector<BigInteger> cipherTextBlocks, BigInteger p, BigInteger q) {
BigInteger n = null, m = null;
Vector<String> decryptedBlocks = new Vector<String>();
Vector<BigInteger> publicKey = new Vector<BigInteger>();
//publicKeys are at the end of the cipher blocks
publicKey.add(cipherTextBlocks.get(cipherTextBlocks.size()-1));
publicKey.add(cipherTextBlocks.get(cipherTextBlocks.size()-2));
//now remove from cipher text
@omarrodriguez15
omarrodriguez15 / gist:052f61298c28594146e3
Created May 5, 2015 20:29
unit test decrypt encrypt blocks
// Test encrypting decrypting multiple blocks
public static void testEncryptDecryptBlocks() {
System.out.println( "Running encryption/decryption of Blocks tests" );
// Create a test
Vector<String> test = new Vector<String>();
for (int i = 5; i < 11; ++i) {
test.add( randomString( (int)Math.pow(2, i) ) );
}
@omarrodriguez15
omarrodriguez15 / myAsyncCall.java
Created December 30, 2015 22:21
Async Class Android
public class myAsyncCall extends AsyncTask<String, Void, String> {
//since this is executing asynchronously want to track local exception
private Exception ex;
//Also since this is not executing on the UI thread we need to get our own instance of UI threads context
private Context mContext;
//Base url to make api calls to
private String baseUrl = "http://api.openweathermap.org/data/2.5/";
private String usrZip = null;
//Constants
@omarrodriguez15
omarrodriguez15 / mainActivity.java
Created December 30, 2015 22:24
Demo Android Activity
public class MainActivity extends AppCompatActivity {
WebView wv1;
Button btnCallWeather;
Button btnCallUrl;
AutoCompleteTextView acTxZip;
AutoCompleteTextView acTxtUrl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
# Mostly following tutorial from just put together into a script for less copy pasta
# http://www.hurryupandwait.io/blog/in-search-of-a-light-weight-windows-vagrant-box
# Automate Setting up VM for Vagrant
##TODO!: Wrap in try catch, finally blocks
#Make sure to set the Execution policy to unrestricted or
#something other than none or restricted
try
{
@omarrodriguez15
omarrodriguez15 / AndroidStudio.gitignore
Created April 28, 2016 18:45
Android studio project gitignore file
# Built application files
/*/build/
build
# Crashlytics configuations
com_crashlytics_export_strings.xml
# Local configuration file (sdk path, etc)
local.properties
@omarrodriguez15
omarrodriguez15 / VideoHandler.cs
Created May 16, 2016 04:02
Displaying video in Xamarin Form
private void PlayVideoFromDisk()
{
var videoView = FindViewById<VideoView> (Resource.Id.videoView1);
//The string concatenated at the end is just a path on the device storage
var videoPath = Environment.ExternalStorageDirectory.AbsolutePath+"/Download/One.mp4";
videoView.SetVideoPath(videoPath);
videoView.RequestFocus();
videoView.Start();
}
@omarrodriguez15
omarrodriguez15 / ActivityCommunicator.cs
Last active June 3, 2016 15:42
Quick example of a way to communicate from outside classes back to an activity. This can be really useful when using fragments. This is for a Xamarin.Android project
namespace Whatever
{
//Basic interface used
interface ICommunicator
{
void UpdateInfo(string data);
}
public class MainActivity : Activity, ICommunicator
{
@omarrodriguez15
omarrodriguez15 / ZipUnZipFolder.ps1
Last active September 7, 2016 19:46
Simple power shell script that takes two arguments "-s" as the source folder name and "-d" as the destination folder name. Only works if the folder is in the working directory.
Param([string]$s="foo",[string]$d="foo")
Add-Type -A System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::CreateFromDirectory(("{0}\\{1}" -f $pwd, $s) , ("{0}\\{1}.zip" -f $pwd, $d))
#[IO.Compression.ZipFile]::ExtractToDirectory(("{0}\\{1}.zip" -f $pwd, $d), ("{0}\\{1}" -f $pwd, $s))