finally on the right track! almost done. implemented everything except decrypting
adding in decryption