Mercurial > mercurial > hgweb_rsearcher.cgi
diff go/crypto.go @ 13:f5ffc34f045a
manage DB.
author | pyon@macmini |
---|---|
date | Wed, 14 Nov 2018 19:43:40 +0900 |
parents | e3b10fb860b3 |
children |
line wrap: on
line diff
--- a/go/crypto.go Tue Nov 13 21:11:20 2018 +0900 +++ b/go/crypto.go Wed Nov 14 19:43:40 2018 +0900 @@ -1,7 +1,7 @@ /* crypto.go : crypto-program. - Version : 0.0 - Last Change: 2018-10-19 金 15:58:10. + Version : 1.1 + Last Change: 2018-11-14 水 13:27:48. install to: rsearcher_root/ server_root/ @@ -26,7 +26,7 @@ var version string func init() { - version = "1.0" + version = "1.1" // output file version } func main() { @@ -40,6 +40,8 @@ decr := flag.String( "d", "", "decrypt hhs." ) ghhs := flag.String( "f", "", "get hhs info." ) + opf := flag.String( "o", "", "output file." ) + pver := flag.Bool( "v", false, "print version." ) flag.Parse() @@ -138,7 +140,8 @@ stream := cipher.NewCTR( block, iv ) stream.XORKeyStream( ciphertext[ aes.BlockSize: ], plaintext ) - fmt.Printf( "%s", ciphertext ) + //fmt.Printf( "%s", ciphertext ) + output( *opf, string( ciphertext ) ) os.Exit( 0 ) } @@ -154,7 +157,8 @@ stream := cipher.NewCTR( block, iv ) stream.XORKeyStream( plaintext, ciphertext[ aes.BlockSize: ] ) - fmt.Printf( "%s", plaintext ) + //fmt.Printf( "%s", plaintext ) + output( *opf, string( plaintext ) ) os.Exit( 0 ) } @@ -175,3 +179,18 @@ return fmt.Sprintf( "%x", h.Sum( nil ) ) } +/* Output Function */ +func output( file, str string ) { + if file == "" { + fmt.Fprint( os.Stdout, str ) + } else { + os.Remove( file ) + f, err := os.OpenFile( file, os.O_RDWR|os.O_CREATE, 0644 ) + if err != nil { + log.Fatal( err ) + } + defer f.Close() + fmt.Fprint( f, str ) + } +} +