Skip to content

Instantly share code, notes, and snippets.

@husobee
husobee / overunder.c
Last active September 10, 2017 21:28
overflow-underflow-casting
#include <stdio.h>
int main() {
// Down Casting an unsigned long to an unsigned char
unsigned long a = 257;
printf("%lu == %d \n", a, (unsigned char)a);
// Output: 257 == 1
// This is obviously not true, but there are not enough bits in a
// char (8 bits) to hold 257, so it will carry over the extra into the value
@husobee
husobee / arithmetic.c
Created September 10, 2017 21:53
arith-overflow
#include <stdio.h>
int main() {
// Given an unsigned char, if we add 1 to the max value an unsigned char can have,
// we strangely get the correct value, which should have overflown the char...
unsigned char a = 255;
printf("%lu + 1 == %d \n", a, a + 1);
// Output: 255 + 1 == 256
// When we take this value and assign it to an unsigned char, and look at the
@husobee
husobee / producer-consumer-problem.go
Created February 6, 2018 12:27
example producer-consumer problem
package main
import (
"errors"
"fmt"
"math/rand"
"time"
)
func init() {
@husobee
husobee / producer-consumer-problem1.go
Created February 6, 2018 12:46
producer-consumer problem with message passing
package main
import (
"errors"
"fmt"
"math/rand"
"time"
)
func init() {
@husobee
husobee / png-lsb-steg.go
Created August 31, 2014 22:23
VERY simplified LSB stego example on PNGs (lossless)
// example of how to hide data in LSB of colors within a lossless png
package main
import (
"errors"
"flag"
"fmt"
"image"
"image/color"
"image/png"
@husobee
husobee / rwmutexvchan_test.go
Created April 3, 2018 19:46
rwmutex-v-chan
package main
import (
"sync"
"testing"
)
type stuff struct {
ret chan string
input string
@husobee
husobee / clww16.go
Created October 24, 2018 20:35
CLWW16 toy project
package main
import (
"crypto/hmac"
"crypto/sha256"
"fmt"
)
func main() {
fmt.Println("Example CLWW 2016 Implementation")
package main
import (
"crypto/hmac"
"crypto/rand"
"crypto/sha1"
"fmt"
"math/big"
)
@husobee
husobee / validation-main.go
Created January 8, 2016 20:07
input validation sanely
package main
import (
"encoding/json"
"errors"
"net/http"
"github.com/asaskevich/govalidator"
)
@husobee
husobee / client_tls_info.go
Last active December 14, 2020 17:52
discovery of tls in go, and the handshake process
package main
import (
"crypto/tls"
"encoding/json"
"fmt"
"log"
"net"
"net/http"
)