Coming to my problem, while checking out all the options in TWRP, I ended up wiping out all data which apparently also erased the OS. I DID NOT BACK UP before this happened and when i reboot it, i see a message "no OS installed".
Then I tried installing a custom ROM with gapps. It was moto's android 8.1 as it was the one i had before. I then had to type a password which I didn't know. But, it says "decryption unsuccessful" and that the file is corrupt. Could anyone please help me with this. I would be forever grateful.