Skip to content

Instantly share code, notes, and snippets.

@pathaine
Last active September 3, 2019 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pathaine/8dc64b5bcd5544a5f3751483afc33996 to your computer and use it in GitHub Desktop.
Save pathaine/8dc64b5bcd5544a5f3751483afc33996 to your computer and use it in GitHub Desktop.
CryptoFractions encrypt_audio(vector<float> signal, int startIndex, int sampleSize, const char *keysFilePath, const long precision) {
vector<int64_t> intSignal;
CryptoFractions encryptedSignal;
int numerator;
int endIndex = startIndex + sampleSize;
for (int i = startIndex; i < endIndex; i += 1) {
numerator = int(signal[i] * precision);
encryptedSignal.numerators.push_back(numerator);
encryptedSignal.denominators.push_back(1);
}
int val;
EncryptionInfo info = read_encryption_info(keysFilePath);
Plaintext signalArray = info.cryptocontext->MakePackedPlaintext(encryptedSignal.numerators);
Plaintext ones = info.cryptocontext->MakePackedPlaintext(encryptedSignal.denominators);
Ciphertext<DCRTPoly> encSignal = info.cryptocontext->Encrypt(info.keypair.publicKey, signalArray);
// For now, the denominator will be 1. We keep track of the precision adjustments separately and deal with that once we are ready to decrypt the result
Ciphertext<DCRTPoly> encSignalDen = info.cryptocontext->Encrypt(info.keypair.publicKey, ones);
encryptedSignal.encryptedNumerators = encSignal;
encryptedSignal.encryptedDenominators = encSignalDen;
return encryptedSignal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment