Contains the source code from the course work throughout my undergraduate Computer Engineering degree at Brigham Young University. There is a mixture of Go, Python, C, C++, Java, VHDL, Verilog, Matlab, Bash, Assembly, etc..
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "os"
  6. "s.mcquay.me/dm/school/cs465/aes"
  7. "github.com/spf13/cobra"
  8. )
  9. var key128 = aes.Block{
  10. 0x2b, 0x28, 0xab, 0x09,
  11. 0x7e, 0xae, 0xf7, 0xcf,
  12. 0x15, 0xd2, 0x15, 0x4f,
  13. 0x16, 0xa6, 0x88, 0x3c,
  14. }
  15. var key192 = aes.Block{
  16. 0x00, 0x04, 0x08, 0x0c, 0x10, 0x14,
  17. 0x01, 0x05, 0x09, 0x0d, 0x11, 0x15,
  18. 0x02, 0x06, 0x0a, 0x0e, 0x12, 0x16,
  19. 0x03, 0x07, 0x0b, 0x0f, 0x13, 0x17,
  20. }
  21. var key256 = aes.Block{
  22. 0x00, 0x04, 0x08, 0x0c, 0x10, 0x14, 0x18, 0x1c,
  23. 0x01, 0x05, 0x09, 0x0d, 0x11, 0x15, 0x19, 0x1d,
  24. 0x02, 0x06, 0x0a, 0x0e, 0x12, 0x16, 0x1a, 0x1e,
  25. 0x03, 0x07, 0x0b, 0x0f, 0x13, 0x17, 0x1b, 0x1f,
  26. }
  27. func main() {
  28. var keysize int
  29. var decrypt bool
  30. var ascii bool
  31. var aes = &cobra.Command{
  32. Use: "aes",
  33. Short: "aes cipher",
  34. Long: `perform aes cipher`,
  35. Run: func(cmd *cobra.Command, args []string) {
  36. if len(args) < 1 {
  37. fmt.Println("missing input, see -h (--help) for more info")
  38. os.Exit(1)
  39. }
  40. for _, arg := range args {
  41. all := aes.BlockGen(arg)
  42. if ascii {
  43. switch keysize {
  44. case 128:
  45. fmt.Println(aes.ToString(all, 128, key128, decrypt))
  46. case 192:
  47. fmt.Println(aes.ToString(all, 192, key192, decrypt))
  48. case 256:
  49. fmt.Println(aes.ToString(all, 256, key256, decrypt))
  50. default:
  51. log.Fatal("keysize not valid")
  52. }
  53. } else {
  54. switch keysize {
  55. case 128:
  56. fmt.Println(aes.ToHex(all, 128, key128, decrypt))
  57. case 192:
  58. fmt.Println(aes.ToHex(all, 192, key192, decrypt))
  59. case 256:
  60. fmt.Println(aes.ToHex(all, 256, key256, decrypt))
  61. default:
  62. log.Fatal("keysize not valid")
  63. }
  64. }
  65. }
  66. },
  67. }
  68. aes.Flags().IntVarP(
  69. &keysize,
  70. "keysize",
  71. "k",
  72. 0,
  73. "keysize",
  74. )
  75. aes.Flags().BoolVarP(
  76. &ascii,
  77. "ascii",
  78. "a",
  79. false,
  80. "display in ascii (may mess up terminal :) )",
  81. )
  82. aes.Flags().BoolVarP(
  83. &decrypt,
  84. "decrypt",
  85. "d",
  86. false,
  87. "decrypt",
  88. )
  89. var rootCmd = &cobra.Command{Use: "app"}
  90. rootCmd.AddCommand(aes)
  91. rootCmd.Execute()
  92. }