cipher static method

List<int> cipher({
  1. required List<int> data,
  2. required int password,
})

Encrypts the given data using a password and security key. The bigger the security key number the safer it is but the longer it takes to compute.

Implementation

static List<int> cipher({required List<int> data,required int password}){
  //Generate private and public keys
  CipherGen generated = CipherGen(seed: password);
  //Encrypt the data
  List<int> cipheredData = [];
  for(int i = 0;i < data.length; i++){
    if(data[i] <= generated.N!){
      //Encrypt and add
      cipheredData.add(data[i].modPow(generated.e!, generated.N!));
      //Check that the computer was able to compute, operations that are to big are registered as infinite
      if(cipheredData[i] == double.infinity){
        throw CipherError.bigPassword;
      }
    }else{
      throw CipherError.smallPassword;
    }
  }
  //Return the encrypted data
  return cipheredData;
}