Re-implementation of cyphering in a better way