Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8809911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:59:36+00:00 2026-06-14T02:59:36+00:00

I am new to programming, and I am trying to write a Vigenère Encryption

  • 0

I am new to programming, and I am trying to write a Vigenère Encryption Cipher using python. The idea is very simple and so is my function, however in this line:

( if((BinKey[i] == 'b')or(BinKey[i+1] == 'b')): ) 

It seems that I have an index problem, and I can’t figure out how to fix it.
The error message is:

IndexError: string index out of range

I tried to replace the i+1 index by another variable equal to i+1, since I thought that maybe python is re-incrementing the i, but it still won’t work.

So my questions are:

  1. How to fix the problem, and what have I done wrong?

  2. Looking at my code, what can I learn to improve my programming skills?

  3. I want to build a simple interface to my program (which will contain all the encryption ciphers), and all I came up with from Google is pyqt, but it just seems too much work for a very simple interface, so is there a simpler way to build an interface? (I am working with Eclipse Indigo and pydev with Python3.x)

The Vigenère Encryption function (which contains the line that causes the problem) is:

def Viegner_Encyption_Cipher(Key,String):
    EncryptedMessage = ""
    i = 0
    j = 0
    BinKey = Bin_It(Key)
    BinString = Bin_It(String)
    BinKeyLengh = len(BinKey)
    BinStringLengh = len(BinString)
    while ((BinKeyLengh > i) and (BinStringLengh > j)):
        if((BinKey[i] == 'b')or(BinKey[i+1] == 'b')):
            EncryptedMessage = EncryptedMessage + BinKey[i]
        else:   
            EncryptedMessage = EncryptedMessage + Xor(BinKey[i],BinString[j])
        i = i + 1
        j = j + 1
        if (i == BinKeyLengh):
            i = i+j
    return EncryptedMessage

This is the Bin_It function:

 def Bin_It(String):
    TheBin = ""
    for Charactere in String:
         TheBin = TheBin + bin(ord(Charactere))
    return TheBin

And finally this is the Xor function:

def Xor(a,b):
    xor = (int(a) and not int(b)) or (not int(a) and int(b))
    if xor:
        return chr(1)
    else:
        return chr(0)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:59:37+00:00Added an answer on June 14, 2026 at 2:59 am

    In your while condition, you are ensuring that i < len(BinKey). This means that BinKey[i] will be valid, but BinKey[i+1] will not be valid at the last iteration of your loop, as you will then be accessing BinKey[len(BinKey)], which is one past the end of your string. Strings in python start at 0 and end at len-1 inclusive.

    To avoid this, you can update your loop criterion to be

    while BinKeyLength > i+1 and ...:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to programming, and I'm trying to write a Python function to find
I am new to socket programming and trying to write a simple cmd line
I'm very new to Web programming and am trying to write a simple application
I'm very new to programming and I am trying to write a program that
I am new to programming. I have been trying to write a function in
i am enthusiast and new in programming trying this simple c language code and
I'm very new to iphone programming. I'm trying to write an application where I
I am new to PHP and am trying to write a simple function that
I am new to programming and trying to write a javascript function to set
I'm new in Android Programming. I'm trying to write an app that uses USB

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.