Skip to content

Instantly share code, notes, and snippets.

🐿
Hiding nuts

Patrick Favre-Bulle patrickfav

🐿
Hiding nuts
Block or report user

Report or block patrickfav

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@patrickfav
patrickfav / encrypt_img_ecb.sh
Created Nov 17, 2018
Encrypt .ppm file with AES-ECB to show ECB will reveal patterns
View encrypt_img_ecb.sh
#!/bin/sh
# This is part of my blog about AES: https://medium.com/p/7616beaaade9
# Inspired by https://blog.filippo.io/the-ecb-penguin/
# Convert your image to .ppm with Gimp or Photoshop
#
# Usage: ./ecb_img <image file as ppm> <password>
# extract header and body
@patrickfav
patrickfav / AesCbcExample.java
Created Nov 11, 2018
Companion code to my article about AES+CBC with Encrypt-then-MAC
View AesCbcExample.java
package at.favre.lib.armadillo;
import org.junit.Test;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.Arrays;
@patrickfav
patrickfav / example_jekyll.md
Last active Apr 30, 2019
A Liquid Filter for obfuscating an Email Address (can be used with Jekyll aswell)
View example_jekyll.md

In Jekyll set a variable for the mail, e.g. in the _config.yml

email: name@mail.com

then use it in your page

Reach me under:	{{ site.email | mailObfuscate }}

which will generate the following HTML

@patrickfav
patrickfav / encoding_info.txt
Last active Apr 28, 2019
Overview of Many Popular Binary-to-Text Encodings
View encoding_info.txt
## Binary
┌─────────────────┬──────────────────────────────────────────────────────────────────┐
│ Efficiency │ 12.5 % (1 bit/char), 1 bit segments │
│ 32/64/128 bit │ 1-32/1-64/1-128 chars │
│ Padding │ false │
│ Const. Out. Len.│ false │
│ Suited for │ number encoding, debugging │
│ Alphabet │ 01 │
│ Known Usages │ none │
@patrickfav
patrickfav / EncodingBenchmark.java
Last active Apr 27, 2019
Simple JMH Benchmark to test Hex vs Base64 Encoding Performance
View EncodingBenchmark.java
import at.favre.lib.bytes.Bytes;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import java.util.concurrent.TimeUnit;
@SuppressWarnings("CheckStyle")
@State(Scope.Thread)
@Fork(1)
@Warmup(iterations = 2, time = 4)
@patrickfav
patrickfav / encoded_compressed_stats.txt
Last active Apr 27, 2019
Statistics for Encoded and Compressed Data
View encoded_compressed_stats.txt
## Random Data
Original size: 1024 byte
Compressed size (raw): 1047 byte
Name enc diff % enc-comp diff
------------------------------------------------------------------
base85 1280 256 23% 1076 29 2%
base64 1366 342 31% 1073 26 2%
base36 1585 561 51% 1082 35 3%
@patrickfav
patrickfav / IdMaskExample1.java
Created Apr 24, 2019
Id Mask 64-Bit Integer Example for Medium Article
View IdMaskExample1.java
byte[] key = Bytes.random(16).array();
long id = ...
IdMask<Long> idMask = IdMasks.forLongIds(Config.builder(key).build());
String maskedId = idMask.mask(id);
//example: NPSBolhMyabUBdTyanrbqT8
long originalId = idMask.unmask(maskedId);
@patrickfav
patrickfav / MultipleOrientationSlidingDrawer.java
Created Aug 20, 2013
My solution for a Sliding Drawer that can come from Top: I extracted SlidingTray from this lib http://aniqroid.sileria.com/doc/api/ (by Ahmed Shakil) and refactored it a bit since it had some quirks needed to be used within this lib. It consists of 1 class and you have to add atts in your attrs.xml. Other than that it has pretty much the same us…
View MultipleOrientationSlidingDrawer.java
package your.app;
/*
* Copyright (c) 2001 - 2012 Sileria, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@patrickfav
patrickfav / BcryptMemoryLeakTest.java
Last active Mar 29, 2019
Very simple test for probable Memory Leak in Bcrypt Library
View BcryptMemoryLeakTest.java
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Tester {
public static String[] pws = {"ZeDRJ:_tu:", "ZeDRJ:_tu1", "ZeDRJ:_tu2", "ZeDRJ:_tu3", "ZeDRJ:_tu4", "ZeD1", "ZeDRJu1", "ZeDRJ:_tu19881", "98asfhj", "adasd", "()=H)d"};
public static Random r = new Random();
public static List<BCrypt.Verifyer> verifyers = new ArrayList<>();
public static boolean introduceMemoryLeak = false;
@patrickfav
patrickfav / sigma-js-angular-app.js
Last active Apr 13, 2018
Simple Sigma.js AngularJs Directive: Since I did not find any angularjs directive for angularjs I created a little simple of my own. This is by no means a ready-for-all solutions, but all the features I needed at the time; it is easily extended to your needs and maybe sometimes somebody will do a full-blown directive for sigma.js Tested: angular…
View sigma-js-angular-app.js
/*
* Copyright 2017 Patrick Favre-Bulle
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
You can’t perform that action at this time.