Esempio n. 1
0
File: RSA.go Progetto: JSoddy/goplay
// Function to write encrypted texts to a file
func writeCipher(message []*big.Int, fileName string) {
	// Create writer and check for error
	file, err := os.Create(fileName)
	if err != nil {
		fmt.Println("\nError, could not open file!\n")
		return
	}
	// close file on exit and check for its returned error
	defer func() {
		if err := file.Close(); err != nil {
			panic(err)
		}
	}()
	// Create a writer on the opened file and write the encrypted
	// data to it with some formatting
	w := bufio.NewWriter(file)
	w.WriteString("----------Message----------\n")
	// iterate over the slice of encrypted messages and write them
	//  on separate lines with dividers
	for _, v := range message {
		w.WriteString(fmt.Sprintln(v))
		w.WriteString("-----------------------------------\n")
	}
	w.WriteString("--------End Message--------\n")
	w.Flush()
	fmt.Printf("\nMessage written to file %s\n", fileName)
}
Esempio n. 2
0
File: RSA.go Progetto: JSoddy/goplay
// Function to write our decrypted plaintexts to a file
func writePlainText(message string, fileName string) {
	// Create writer and check for error
	file, err := os.Create(fileName)
	if err != nil {
		fmt.Println("\nError, could not open file!\n")
		return
	}
	// close file on exit and check for its returned error
	defer func() {
		if err := file.Close(); err != nil {
			panic(err)
		}
	}()
	// Output the string to a file, with a little formatting
	w := bufio.NewWriter(file)
	w.WriteString("----------Message----------\n")
	w.WriteString(fmt.Sprintln(message))
	w.WriteString("--------End Message--------\n")
	w.Flush()
	fmt.Printf("\nMessage written to file %s\n", fileName)
}
Esempio n. 3
0
File: RSA.go Progetto: JSoddy/goplay
// Function to write encryption keys into a file
func writeKey(modulus, exponent *big.Int, fileName string) {
	// Create writer and check for error
	file, err := os.Create(fileName)
	if err != nil {
		fmt.Println("\nError, could not open file!")
		return
	}
	// close file on exit and check for its returned error
	defer func() {
		if err := file.Close(); err != nil {
			panic(err)
		}
	}()
	// Write out the modulus and exponent with a little formatting to make
	//  it more readable
	w := bufio.NewWriter(file)
	w.WriteString("----------Modulus----------\n")
	w.WriteString(fmt.Sprintln(modulus))
	w.WriteString("--------End Modulus--------\n")
	w.WriteString("----------Exponent---------\n")
	w.WriteString(fmt.Sprintln(exponent))
	w.WriteString("-------End Exponent--------\n")
	w.Flush()
}