pub fn encrypt(
    _pk: &KpAbePublicKey,
    _attributes: &Vec<String>,
    _plaintext: &[u8],
) -> Option<KpAbeCiphertext> {
    if _attributes.is_empty() || _plaintext.is_empty() {
        return None;
    } else {
        // random number generator
        let mut _rng = rand::thread_rng();
        // attribute vector
        let mut _ej: Vec<(String, G1, G1, G1)> = Vec::new();
        // random secret
        let _s:Fr = _rng.gen();
        // sx vector
        let mut _sx: Vec<Fr> = Vec::new();
        _sx.push(_s);
        for (_i, _attr) in _attributes.iter().enumerate() {
            _sx.push(_rng.gen());
            _sx[0] = _sx[0] - _sx[_i];
        }
        for (_i, _attr) in _attributes.into_iter().enumerate() {
            _ej.push((
                _attr.to_string(),
                blake2b_hash_g1(_pk._g_g1, &_attr) * _s,
                _pk._g_g1_b * _sx[_i],
                (_pk._g_g1_b2 * (_sx[_i] * blake2b_hash_fr(&_attr))) + (_pk._h_g1_b * _sx[_i]),
            ));
        }
        // random message
        let _msg: Gt = _rng.gen();
        let _e1 = _pk._e_gg_alpha.pow(_s) * _msg;
        let _e2 = _pk._g_g2 * _s;
        let _ct = encrypt_symmetric(&_msg, &_plaintext.to_vec()).unwrap();
        //Encrypt plaintext using derived key from secret
        Some(KpAbeCiphertext {_e1, _e2, _ej, _ct})
    }
}
/// The encrypt algorithm of LSW KP-ABE. Generates a new KpAbeCiphertext using an KpAbePublicKey, a set of attributes given as String Vector and some plaintext data given as [u8].
///
/// # Arguments
///
///	* `_pk` - A Public Key (PK), generated by the function setup()
///	* `_attributes` - A set of attributes given as String Vector
///	* `_plaintext` - plaintext data given as a Vector of u8
///
The encrypt algorithm of LSW KP-ABE. Generates a new KpAbeCiphertext using an KpAbePublicKey, a set of attributes given as String Vector and some plaintext data given as [u8].
The encrypt algorithm of LSW KP - ABE . Generates a new KpAbeCiphertext using an KpAbePublicKey a set of attributes given as String Vector and some plaintext data given as [ u8 ] .
pub fn encrypt(
    _pk: &KpAbePublicKey,
    _attributes: &Vec<String>,
    _plaintext: &[u8],
) -> Option<KpAbeCiphertext> {
    if _attributes.is_empty() || _plaintext.is_empty() {
        return None;
    } else {
        // random number generator
        let mut _rng = rand::thread_rng();
        // attribute vector
        let mut _ej: Vec<(String, G1, G1, G1)> = Vec::new();
        // random secret
        let _s:Fr = _rng.gen();
        // sx vector
        let mut _sx: Vec<Fr> = Vec::new();
        _sx.push(_s);
        for (_i, _attr) in _attributes.iter().enumerate() {
            _sx.push(_rng.gen());
            _sx[0] = _sx[0] - _sx[_i];
        }
        for (_i, _attr) in _attributes.into_iter().enumerate() {
            _ej.push((
                _attr.to_string(),
                blake2b_hash_g1(_pk._g_g1, &_attr) * _s,
                _pk._g_g1_b * _sx[_i],
                (_pk._g_g1_b2 * (_sx[_i] * blake2b_hash_fr(&_attr))) + (_pk._h_g1_b * _sx[_i]),
            ));
        }
        // random message
        let _msg: Gt = _rng.gen();
        let _e1 = _pk._e_gg_alpha.pow(_s) * _msg;
        let _e2 = _pk._g_g2 * _s;
        let _ct = encrypt_symmetric(&_msg, &_plaintext.to_vec()).unwrap();
        //Encrypt plaintext using derived key from secret
        Some(KpAbeCiphertext {_e1, _e2, _ej, _ct})
    }
}
pub fn encrypt ( _pk : & KpAbePublicKey , _attributes : & Vec < String > , _plaintext : & [ u8 ] , ) -> Option < KpAbeCiphertext > { if _attributes . is_empty ( ) || _plaintext . is_empty ( ) { return None ; } else { // random number generator let mut _rng = rand :: thread_rng ( ) ; // attribute vector let mut _ej : Vec < ( String , G1 , G1 , G1 ) > = Vec :: new ( ) ; // random secret let _s : Fr = _rng . gen ( ) ; // sx vector let mut _sx : Vec < Fr > = Vec :: new ( ) ; _sx . push ( _s ) ; for ( _i , _attr ) in _attributes . iter ( ) . enumerate ( ) { _sx . push ( _rng . gen ( ) ) ; _sx [ 0 ] = _sx [ 0 ] - _sx [ _i ] ; } for ( _i , _attr ) in _attributes . into_iter ( ) . enumerate ( ) { _ej . push ( ( _attr . to_string ( ) , blake2b_hash_g1 ( _pk . _g_g1 , & _attr ) * _s , _pk . _g_g1_b * _sx [ _i ] , ( _pk . _g_g1_b2 * ( _sx [ _i ] * blake2b_hash_fr ( & _attr ) ) ) + ( _pk . _h_g1_b * _sx [ _i ] ) , ) ) ; } // random message let _msg : Gt = _rng . gen ( ) ; let _e1 = _pk . _e_gg_alpha . pow ( _s ) * _msg ; let _e2 = _pk . _g_g2 * _s ; let _ct = encrypt_symmetric ( & _msg , & _plaintext . to_vec ( ) ) . unwrap ( ) ; //Encrypt plaintext using derived key from secret Some ( KpAbeCiphertext { _e1 , _e2 , _ej , _ct } ) } }
The encrypt algorithm of LSW KP-ABE.
The encrypt algorithm of LSW KP - ABE .
_pk
&KpAbePublicKey
_attributes
&Vec<String>
_plaintext
&[u8]
_pk
&KpAbePublicKey
_attributes
&Vec<String>
_plaintext
&[u8]