Advertisement
Guest User

vignere_5_bruteforcer

a guest
Sep 15th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.69 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "strconv"
  6.     "os/exec"
  7.     //"log"
  8.     "strings"
  9.     "sync"
  10.     //"math"
  11.     )
  12.  
  13. func test_keys(keyset []string, worker_id int) {
  14.     fmt.Println("Worker " + strconv.Itoa(worker_id) + " started.")
  15.     var keys_tested = 0
  16.     for _, key := range keyset {
  17.         command := strings.Split("/home/john/Documents/College/Fa18/CMPEN443/Assignments/cmpsc443cipher/cmpsc443cipher -d -i /home/john/Documents/College/Fa18/CMPEN443/Assignments/cmpsc443cipher/jdh5658_vigenere_encrypted.txt -c vigenere -k " + key, " ")
  18.         cmd := exec.Command(command[0], command[1:]...)
  19.         out, err := cmd.CombinedOutput()
  20.         keys_tested += 1
  21.  
  22.         if err != nil {
  23.             fmt.Println(err)
  24.             fmt.Println(string(out))
  25.         } else if strings.Contains(string(out), "successfully") {
  26.             fmt.Println("KEY HAS BEEN FOUND: " + key)
  27.             return
  28.         } else {
  29.             if keys_tested % 100000 == 0 {
  30.                 fmt.Println(string(out))
  31.                 fmt.Println(strconv.Itoa(keys_tested))
  32.             }
  33.         }
  34.     }
  35. }
  36.  
  37. func main() {
  38.     keys := make([]string, 0)
  39.  
  40.     var alphabet = `ABCDEFGHIJKLMNOPQRSTUVWXYZ`
  41.  
  42.     fmt.Println("Generating keys...")
  43.  
  44.     for _, c := range alphabet {
  45.         for _, d := range alphabet {
  46.             for _, e := range alphabet {
  47.                 for _, f := range alphabet {
  48.                     for _, g := range alphabet {
  49.                         keys = append(keys, string(c) + string(d) + string(e) + string(f) + string(g))
  50.                     }
  51.                 }
  52.             }
  53.         }
  54.     }
  55.  
  56.     fmt.Println("Key generation finished.  Starting worker threads to test...")
  57.  
  58.     var partition_1 = 3960458
  59.     var partition_2 = 7920917
  60.  
  61.     var wait_group sync.WaitGroup
  62.     wait_group.Add(3)
  63.  
  64.     go test_keys(keys[0:partition_1], 0)
  65.     go test_keys(keys[partition_1+1:partition_2], 1)
  66.     go test_keys(keys[partition_2+1:len(keys)], 2)
  67.  
  68.     wait_group.Wait()
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement