Ransomeware v Time machine and iCloud
Well, if your Time Machine or iCloud backup was done before some ransomeware encrypted your hard drive, and assuming that the ransomeware didn't also encrypt your backup, then yes, you can restore from backup once you got rid of the ransomeware (probably by restoring your Mac from scratch).