Advertisement
Guest User

ref

a guest
Jun 14th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.83 KB | None | 0 0
  1. package main
  2. import (
  3.     "bufio"
  4.     "fmt"
  5.     "os"
  6. )
  7. const eol = 13
  8. var input *bufio.Reader
  9. func cap(b byte) byte {
  10.     if b >= 'a' {
  11.         return b - 'a' + 'A'
  12.     }
  13.     return b
  14. }
  15. func dictate(t chan byte) {
  16.     for {
  17.         b, _ := input.ReadByte()
  18.         t <- b
  19.         if b == eol {
  20.             break
  21.         }
  22.     }
  23. }
  24. func encrypt(t, c chan byte) {
  25.     for {
  26.         b := <-t
  27.         if b == ' ' || b == '.' || b == eol {
  28.             c <- b
  29.         } else if cap(b) < 'X' {
  30.             c <- b + 3
  31.         } else {
  32.             c <- b - 23
  33.         }
  34.     }
  35. }
  36. func send(c chan byte, d chan bool) {
  37.     b := byte(0)
  38.     for b != eol {
  39.         b = <-c
  40.         fmt.Print(string(b))
  41.     }
  42.     fmt.Println()
  43.     d <- true
  44. }
  45.  
  46.  
  47. func main() {
  48.     input = bufio.NewReader(os.Stdin)
  49.     textchan := make(chan byte)
  50.     cryptchan := make(chan byte)
  51.     done := make(chan bool)
  52.     go dictate(textchan)
  53.     go encrypt(textchan, cryptchan)
  54.     go send(cryptchan, done)
  55.     <-done
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement