# Vigenere

starting the challenge we were told about vigenere cipher so i started learning about vigenere cipher so its similar to caesar cipher but the difference is that we are gonna use a key that will repeat until we make the cipher text hope you understand what im saying

so we just need to map all of the possibilities then decrypt using that

```python
import string
instr = ""
with open('cipher.txt', 'r') as a:
    instr = a.readline().strip()

key = "CYLAB"
outstr = ""
offset_lower = ord('a')
offset_upper = ord('A')
lower = string.ascii_lowercase
upper = string.ascii_uppercase

dicts_l={}

for k in key:
    key_loc = ord(k)-offset_upper
    dicts_l[k] = {}
    for l in lower:
        cipher = chr((ord(l) - offset_lower + key_loc) % 26 + offset_lower)
        dicts_l[k][cipher] = l

dicts_u = {}

for k in key:
    key_loc = ord(k) - offset_upper
    dicts_u[k] = {}
    for u in upper:
        dicts_u[k][chr((ord(u) - offset_upper + key_loc) % 26 + offset_upper)] = u

count=0
for c in instr:
    if c.isalpha():
        if c.islower():
            outstr += dicts_l[key[count % len(key)]][c]
        elif c.isupper():
            outstr += dicts_u[key[count % len(key)]][c]
        count += 1
    else:
        outstr += c
print(outstr)
```

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FFAIMXK2l3WSYzDPHYQJP%2Fimage.png?alt=media&#x26;token=d9dbbc0e-35c6-4dee-9358-b811ce6c75f3" alt=""><figcaption></figcaption></figure>
