I understand encryption in mediums outside digital stuff like letters or Morse code, but how does a computer OS works when its code is scrambled, and how is the key stored and used to verify the enryption passphrase without some pluck it out and use it.
Encrypted letters don’t have to carry the key or verify it.
At the simplest level: An encryption algorithm doesn’t concern itself with whether or not the right key was provided*. It takes a key, some encrypted data, and then spits out whethever the math says it should.
Programmers will build on top of an algorithm to add more complex security features. An example of which might be “Tell the user whether or not their key actually worked” or “Tell the user if someone tampered with the encrypted data”.
The actual implementation of these security features is different for every situation, and can get quite complex.
Here is a very simple example of what someone might do:
Then when decrypting, you look for the word “sentinel” at the beginning, and then spit back everything after that. If the word “sentinel” isn’t the first thing you see, then you know the key is incorrect.
In the case of AES algorithm, it has a special way of padding the plaintext before encrypting. If the padding doesn’t show up after decrypting, then the key is incorrect.
* A general statement, not necessarily representative of common encryption algorithms