This is known as a known-plaintext attack. From the Wikipedia article quoted above:
The known-plaintext attack (KPA) is an attack model for cryptanalysis
where the attacker has access to both the plaintext (called a crib),
and its encrypted version (ciphertext). These can be used to reveal
further secret information such as secret keys and code books.
Modern encryption algorithms such as AES are designed to be highly resistant to known-plaintext attacks, however earlier encryption algorithms were susceptible to known-plaintext attacks. For example, with XOR encryption, it is trivial to find the encryption key given the ciphertext and the plaintext.