Last active
September 3, 2019 20:03
-
-
Save pathaine/8dc64b5bcd5544a5f3751483afc33996 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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