Required tools for playing around with memory:
hexdump
objdump
readelf
xxd
gcore
from lps import gen_lps # reference lps.py | |
def kmp_search(pat, txt): | |
N = len(txt) | |
M = len(pat) | |
lps = gen_lps(pat) | |
print('here', lps) | |
i, j = 0, 0 |
def gen_lps(pat): | |
M = len(pat) # length of pat | |
current_len_of_lps = 0 # length of the previous longest prefix suffix | |
lps = [0]*M | |
if M == 1: | |
return lps | |
for i in range(1, M): | |
if pat[i] == pat[current_len_of_lps]: | |
current_len_of_lps += 1 | |
lps[i] = current_len_of_lps |
func GBKToUTF8(data []byte) []byte { | |
UTF8Reader := transform.NewReader(bytes.NewReader(data), simplifiedchinese.GBK.NewDecoder()) | |
b, e := ioutil.ReadAll(UTF8Reader) | |
if e != nil { | |
log.Error("read GBKReader failed, error: %s, GBKReader: %v", e.Error(), UTF8Reader) | |
return nil | |
} | |
return b | |
} |
func ip2int(ip string) uint32 { | |
IP := net.ParseIP(ip) | |
if len(IP) >= 16 { | |
return binary.BigEndian.Uint32(IP[12:16]) | |
} else { | |
return 0 | |
} | |
} |
#include <stdio.h> | |
void pbits(char); | |
int main() { | |
int n = 1025; | |
char* p = (char*)&n; | |
for (int i = 0; i < sizeof(n); i++) { | |
printf("%d byte: ", i); |
# tcpdump the localhost port to a pcap file | |
tcpdump -i lo 'port 3000' -w result.pcap | |
# view the pcap file using tcpdump | |
tcpdump -qns 0 -A -r result.pcap | |
# tcpdump the to dest host package to a pcap file | |
tcpdump -i eth1 -vv -n dst host 9.78.206.6 -w result.pcap |
#!/bin/sh | |
# Create message to be encrypted | |
echo "Creating message file" | |
echo "---------------------" | |
echo "My secret message" > message.txt | |
echo "done\n" | |
# Create asymmetric keypair | |
echo "Creating asymmetric key pair" | |
echo "----------------------------" |
package main | |
import ( | |
"container/list" | |
"fmt" | |
"time" | |
"math/rand" | |
) | |
func init() { | |
rand.Seed(time.Now().UnixNano()) |
var config = make(map[string]interface{}) | |
func loadConfig(path string) (err error) { | |
if _, err := os.Stat(path); os.IsNotExist(err) { | |
log.Fatal("config file path is not exist") | |
} | |
file, err := os.Open(path) | |
if err != nil { | |
log.Fatal("can not open: ", path) |