xor with pwd

main
Robert 2 years ago
parent f2f3c1aff1
commit ecade0ea0a
  1. 1
      .gitignore
  2. 14
      README.MD
  3. 2
      create_db.go
  4. 19
      readData.go
  5. 26
      writeData.go

1
.gitignore vendored

@ -1,2 +1,3 @@
english_words.db english_words.db
rnd-english
*.txt *.txt

@ -3,9 +3,15 @@
## Install ## Install
``` ```
$ go get github.com/mattn/go-sqlite3 $ go get github.com/mattn/go-sqlite3
# Randomize the dictionary
$ shuf /usr/share/dict/american-english > rnd-english
$ go run create_db.go $ go run create_db.go
``` ```
## Create xored data ### Passwords are ONLY for custom words not in the dictionary
$ go run writeData.go ### Enter one keyword at a time for security!!
## Fetch data ## Create encoded data
$ go run readData.go $ go run writeData.go -pwd MyPa$$word
## Fetch data from encodings
$ go run readData.go -pwd MyPa$$word
## Share your rnd-english dictionary with others to be able to see the data.

@ -60,7 +60,7 @@ func main() {
fmt.Println("Top English words inserted into the database.") fmt.Println("Top English words inserted into the database.")
// Read the contents of the american-english file // Read the contents of the american-english file
filePath := "/usr/share/dict/american-english" filePath := "./rnd-english"
content, err := ioutil.ReadFile(filePath) content, err := ioutil.ReadFile(filePath)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

@ -25,6 +25,7 @@ func containsSymbol(input string, symbols []string) bool {
func main() { func main() {
// Define a command-line flag for the filename // Define a command-line flag for the filename
filenamePtr := flag.String("file", "results.txt", "Name of the file to write results to") filenamePtr := flag.String("file", "results.txt", "Name of the file to write results to")
pwdPtr := flag.String("pwd", "", "Enter a password")
flag.Parse() flag.Parse()
// Open the SQLite3 database file // Open the SQLite3 database file
@ -56,11 +57,16 @@ func main() {
// Split the line by spaces // Split the line by spaces
parts := strings.Fields(line) parts := strings.Fields(line)
last := "" last := ""
input := ""
// Process the parsed values (assuming each line has a specific structure) // Process the parsed values (assuming each line has a specific structure)
for _, part := range parts { for _, part := range parts {
if strings.Contains(part, "_") { if strings.Contains(part, "_") {
result := strings.Replace(part, "_", "", -1) result := strings.Replace(part, "_", "", -1)
input := decompressRLE(xorBy13(result)) if (*pwdPtr != "") {
input = decompressRLE(xorStringWithPassword(result, *pwdPtr))
} else {
input = decompressRLE(xorBy13(result))
}
if containsSymbol(input, symbols) { if containsSymbol(input, symbols) {
last = strings.TrimRight(last, " ") + fmt.Sprintf("%s ", input) last = strings.TrimRight(last, " ") + fmt.Sprintf("%s ", input)
} else { } else {
@ -118,6 +124,17 @@ func decompressRLE(compressed string) string {
return result return result
} }
func xorStringWithPassword(input string, password string) string {
inputBytes := []byte(input)
passwordBytes := []byte(password)
for i := 0; i < len(inputBytes); i++ {
inputBytes[i] ^= passwordBytes[i%len(passwordBytes)]
}
return string(inputBytes)
}
func xorBy13(input string) string { func xorBy13(input string) string {
var result strings.Builder var result strings.Builder

@ -20,6 +20,7 @@ var symbols = []string{
func main() { func main() {
// Define a command-line flag for the filename // Define a command-line flag for the filename
filenamePtr := flag.String("file", "results.txt", "Name of the file to write results to") filenamePtr := flag.String("file", "results.txt", "Name of the file to write results to")
pwdPtr := flag.String("pwd", "", "Enter a password")
flag.Parse() flag.Parse()
// Open the SQLite3 database file // Open the SQLite3 database file
@ -62,12 +63,16 @@ func main() {
defer rows.Close() defer rows.Close()
if rows.Next() { if rows.Next() {
// Process the results // Process the results
fmt.Println("Results for case-insensitive LIKE:") //fmt.Println("Results for case-insensitive LIKE:")
writeResultsToFile(*filenamePtr, rows) writeResultsToFile(*filenamePtr, rows)
} else { } else {
if strings.Contains(searchTerm, "*") { if strings.Contains(searchTerm, "*") {
result := strings.Replace(searchTerm, "*", "", -1) result := strings.Replace(searchTerm, "*", "", -1)
if (*pwdPtr != "") {
writeDataToFile(*filenamePtr, xorStringWithPassword(compressRLE(result), *pwdPtr))
} else {
writeDataToFile(*filenamePtr, xorBy13(compressRLE(result))) writeDataToFile(*filenamePtr, xorBy13(compressRLE(result)))
}
} else { } else {
fmt.Println("Not found! Please retype and add an * at the end to save") fmt.Println("Not found! Please retype and add an * at the end to save")
} }
@ -75,7 +80,7 @@ func main() {
} }
} else { } else {
// Process the results // Process the results
fmt.Println("Results for case-sensitive LIKE:") //fmt.Println("Results for case-sensitive LIKE:")
writeResultsToFile(*filenamePtr, rows) writeResultsToFile(*filenamePtr, rows)
} }
} }
@ -94,7 +99,7 @@ func writeDataToFile(filename string, data string) {
log.Fatal(err) log.Fatal(err)
} }
fmt.Printf("Added to %s\n", filename) //fmt.Printf("Added to %s\n", filename)
} }
func writeResultsToFile(filename string, rows *sql.Rows) { func writeResultsToFile(filename string, rows *sql.Rows) {
@ -109,7 +114,7 @@ func writeResultsToFile(filename string, rows *sql.Rows) {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
fmt.Printf("ID=%d\n", id) fmt.Printf("Added ID %d\n", id)
result := fmt.Sprintf("%d ", id) result := fmt.Sprintf("%d ", id)
_, err = file.WriteString(result) _, err = file.WriteString(result)
@ -120,7 +125,7 @@ func writeResultsToFile(filename string, rows *sql.Rows) {
if err := rows.Err(); err != nil { if err := rows.Err(); err != nil {
log.Fatal(err) log.Fatal(err)
} }
fmt.Printf("Results written to %s\n", filename) //fmt.Printf("Results written to %s\n", filename)
} }
func xorBy13(input string) string { func xorBy13(input string) string {
@ -134,6 +139,17 @@ func xorBy13(input string) string {
return result.String() return result.String()
} }
func xorStringWithPassword(input string, password string) string {
inputBytes := []byte(input)
passwordBytes := []byte(password)
for i := 0; i < len(inputBytes); i++ {
inputBytes[i] ^= passwordBytes[i%len(passwordBytes)]
}
return string(inputBytes)
}
// compressRLE compresses a string using Run-Length Encoding // compressRLE compresses a string using Run-Length Encoding
func compressRLE(input string) string { func compressRLE(input string) string {
result := "" result := ""

Loading…
Cancel
Save