diff --git a/.gitignore b/.gitignore index b0b4c8c..8a6f669 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ english_words.db +rnd-english *.txt diff --git a/README.MD b/README.MD index e249206..aff8269 100644 --- a/README.MD +++ b/README.MD @@ -3,9 +3,15 @@ ## Install ``` $ go get github.com/mattn/go-sqlite3 +# Randomize the dictionary +$ shuf /usr/share/dict/american-english > rnd-english $ go run create_db.go ``` -## Create xored data -$ go run writeData.go -## Fetch data -$ go run readData.go +### Passwords are ONLY for custom words not in the dictionary +### Enter one keyword at a time for security!! +## Create encoded data +$ 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. diff --git a/create_db.go b/create_db.go index 9c809fe..e41878f 100644 --- a/create_db.go +++ b/create_db.go @@ -60,7 +60,7 @@ func main() { fmt.Println("Top English words inserted into the database.") // Read the contents of the american-english file - filePath := "/usr/share/dict/american-english" + filePath := "./rnd-english" content, err := ioutil.ReadFile(filePath) if err != nil { log.Fatal(err) diff --git a/readData.go b/readData.go index 4b62c67..6132b4a 100644 --- a/readData.go +++ b/readData.go @@ -25,6 +25,7 @@ func containsSymbol(input string, symbols []string) bool { func main() { // Define a command-line flag for the filename filenamePtr := flag.String("file", "results.txt", "Name of the file to write results to") + pwdPtr := flag.String("pwd", "", "Enter a password") flag.Parse() // Open the SQLite3 database file @@ -56,11 +57,16 @@ func main() { // Split the line by spaces parts := strings.Fields(line) last := "" + input := "" // Process the parsed values (assuming each line has a specific structure) for _, part := range parts { if strings.Contains(part, "_") { 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) { last = strings.TrimRight(last, " ") + fmt.Sprintf("%s ", input) } else { @@ -118,6 +124,17 @@ func decompressRLE(compressed string) string { 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 { var result strings.Builder diff --git a/writeData.go b/writeData.go index b6486ef..e5e5483 100644 --- a/writeData.go +++ b/writeData.go @@ -20,6 +20,7 @@ var symbols = []string{ func main() { // Define a command-line flag for the filename filenamePtr := flag.String("file", "results.txt", "Name of the file to write results to") + pwdPtr := flag.String("pwd", "", "Enter a password") flag.Parse() // Open the SQLite3 database file @@ -62,12 +63,16 @@ func main() { defer rows.Close() if rows.Next() { // Process the results - fmt.Println("Results for case-insensitive LIKE:") + //fmt.Println("Results for case-insensitive LIKE:") writeResultsToFile(*filenamePtr, rows) } else { if strings.Contains(searchTerm, "*") { result := strings.Replace(searchTerm, "*", "", -1) - writeDataToFile(*filenamePtr, xorBy13(compressRLE(result))) + if (*pwdPtr != "") { + writeDataToFile(*filenamePtr, xorStringWithPassword(compressRLE(result), *pwdPtr)) + } else { + writeDataToFile(*filenamePtr, xorBy13(compressRLE(result))) + } } else { fmt.Println("Not found! Please retype and add an * at the end to save") } @@ -75,7 +80,7 @@ func main() { } } else { // Process the results - fmt.Println("Results for case-sensitive LIKE:") + //fmt.Println("Results for case-sensitive LIKE:") writeResultsToFile(*filenamePtr, rows) } } @@ -94,7 +99,7 @@ func writeDataToFile(filename string, data string) { log.Fatal(err) } - fmt.Printf("Added to %s\n", filename) + //fmt.Printf("Added to %s\n", filename) } func writeResultsToFile(filename string, rows *sql.Rows) { @@ -109,7 +114,7 @@ func writeResultsToFile(filename string, rows *sql.Rows) { if err != nil { log.Fatal(err) } - fmt.Printf("ID=%d\n", id) + fmt.Printf("Added ID %d\n", id) result := fmt.Sprintf("%d ", id) _, err = file.WriteString(result) @@ -120,7 +125,7 @@ func writeResultsToFile(filename string, rows *sql.Rows) { if err := rows.Err(); err != nil { log.Fatal(err) } - fmt.Printf("Results written to %s\n", filename) + //fmt.Printf("Results written to %s\n", filename) } func xorBy13(input string) string { @@ -134,6 +139,17 @@ func xorBy13(input string) 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 func compressRLE(input string) string { result := ""