func loadDictionary(fileName string) dictionary { dict := dictionary{} //read file lines input := file.FileLines(fileName) // break out first line, load its values into size dict.size = intSeparate(input[0]) input = input[1:] // break out second line, load it into basic dict.basic = intSeparate(input[0]) input = input[1:] // break out third line, load it into nonBasic dict.nonBasic = intSeparate(input[0]) input = input[1:] // break out fourth line, load it into coeff dict.coeff = floatSeparate(input[0]) input = input[1:] // for next size[0] lines, load into matrix dict.matrix = make([][]float64, dict.size[0]) for i := 0; i < dict.size[0]; i++ { dict.matrix[i] = floatSeparate(input[0]) input = input[1:] } // load final line into objective dict.objective = floatSeparate(input[0]) return dict }
// Function to read encryption keys from a file func readKey(fileName string) (*big.Int, *big.Int, error) { // Get the contents of file as a slice of strings keyStrings, err := file.FileLines(fileName) // If we ran into an i/o error, tell user and return if err != nil { fmt.Println("\nError, key could not be read from file") return nil, nil, err } // indices 1 and 4 of the keyfile will hold the modulus and exponent modulus, _ := big.NewInt(0).SetString(keyStrings[1], 0) exponent, _ := big.NewInt(0).SetString(keyStrings[4], 0) // Return to the user return modulus, exponent, nil }
func loadGraph() Graph { fileLines := file.FileLines(fileToken) dataLine := strings.Split(fileLines[0], "\n") dataLine = strings.Split(dataLine[0], "\r") nodeCount, _ := strconv.Atoi(dataLine[0]) fileLines = fileLines[1:] graph := make(Graph, nodeCount) for i, v := range fileLines { graph[i] = readNode(v) } graph = calculateEdges(graph) return graph }
// Function to read in an encrypted ciphertext from a file func readCipher(fileName string) []*big.Int { // Read the file in as a slice of strings cipherStrings, err := file.FileLines(fileName) // If there was an error, let the user know and return if err != nil { fmt.Println("\nError, ciphertext could not be read from file!") return nil } // Create a slice of big Ints to hold our ciphertext cipherText := make([]*big.Int, 0) // Every second line, except the last, should hold an encrypted // chunk of data - convert them to big Ints and store them for i := 1; i < len(cipherStrings)-2; i += 2 { next, _ := big.NewInt(0).SetString(cipherStrings[i], 0) cipherText = append(cipherText, next) } return cipherText }