-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.go
More file actions
132 lines (108 loc) · 3.66 KB
/
main.go
File metadata and controls
132 lines (108 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"fmt"
"log"
"github.com/aliengiraffe/deidentify"
)
func main() {
// Generate a secure secret key
secretKey, err := deidentify.GenerateSecretKey()
if err != nil {
log.Fatal("Failed to generate secret key:", err)
}
// Create a new deidentifier with default options
d := deidentify.NewDeidentifier(secretKey)
// Example text containing various PII
text := `From: Legolas Greenleaf <legolas@mirkwood.elf>
To: White Council Support
Subject: Ring Information
Hello,
My name is Legolas Greenleaf and I need help with my quest.
My phone number is (555) 123-4567 and my SSN is 123-45-6789.
My friend's social security number is 123 45 6789 and my assistant's SSN is 987654321.
I made a payment using my credit card 4111-1111-1111-1111 yesterday.
I live at 15 Woodland Realm, Mirkwood Forest, Middle-earth.
Thanks,
Legolas`
// Simple deidentification
redacted, err := d.Text(text)
if err != nil {
log.Fatal("Failed to deidentify text:", err)
}
fmt.Println("Original text:")
fmt.Println("--------------------------------------")
fmt.Println(text)
fmt.Println("\nDeidentified text:")
fmt.Println("--------------------------------------")
fmt.Println(redacted)
// Demonstrate type-specific deidentification
fmt.Println("\nType-specific deidentification:")
fmt.Println("--------------------------------------")
email := "legolas@mirkwood.elf"
redactedEmail, err := d.Email(email)
if err != nil {
log.Fatal("Failed to deidentify email:", err)
}
fmt.Printf("Email: %s → %s\n", email, redactedEmail)
phone := "(555) 123-4567"
redactedPhone, err := d.Phone(phone)
if err != nil {
log.Fatal("Failed to deidentify phone:", err)
}
fmt.Printf("Phone: %s → %s\n", phone, redactedPhone)
// Test different SSN formats
ssnFormats := []string{
"123-45-6789", // With hyphens
"123 45 6789", // With spaces
"123456789", // Without separators
}
for _, ssn := range ssnFormats {
redactedSSN, err := d.SSN(ssn)
if err != nil {
log.Fatal("Failed to deidentify SSN:", err)
}
fmt.Printf("SSN: %s → %s\n", ssn, redactedSSN)
}
address := "15 Woodland Realm, Mirkwood Forest"
redactedAddress, err := d.Address(address)
if err != nil {
log.Fatal("Failed to deidentify address:", err)
}
fmt.Printf("Address: %s → %s\n", address, redactedAddress)
name := "Legolas Greenleaf"
redactedName, err := d.Name(name)
if err != nil {
log.Fatal("Failed to deidentify name:", err)
}
fmt.Printf("Name: %s → %s\n", name, redactedName)
// Demonstrating consistency - same input produces same output
fmt.Println("\nConsistency demonstration:")
fmt.Println("--------------------------------------")
anotherEmail := "legolas@mirkwood.elf" // Same email as before
redactedAgain, _ := d.Email(anotherEmail)
fmt.Printf("Same input produces same output: %v\n",
redactedEmail == redactedAgain)
// Demonstrate the variety of generated values
fmt.Println("\nDemonstrating data variety:")
fmt.Println("--------------------------------------")
// Create another deidentifier with a different key
d2 := deidentify.NewDeidentifier("different-secret-key")
fmt.Println("Names:")
for i := 0; i < 5; i++ {
sampleName := fmt.Sprintf("Sample Person %d", i)
redacted, _ := d2.Name(sampleName)
fmt.Printf(" %s → %s\n", sampleName, redacted)
}
fmt.Println("\nEmails:")
for i := 0; i < 5; i++ {
sampleEmail := fmt.Sprintf("person%d@example.com", i)
redacted, _ := d2.Email(sampleEmail)
fmt.Printf(" %s → %s\n", sampleEmail, redacted)
}
fmt.Println("\nAddresses:")
for i := 0; i < 5; i++ {
sampleAddress := fmt.Sprintf("%d Example Street", 100+i)
redacted, _ := d2.Address(sampleAddress)
fmt.Printf(" %s → %s\n", sampleAddress, redacted)
}
}