When running my code, I get a "substring not found" not entirely sure what that means..here is my code:\

filename = open('code.txt','r').read()
string = filename
def decode(string):
    abc='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    n=1
    result=''
    for rotate in string:
        result+=abc[(abc.index(rotate)-n)%26] 
        n+=1
    print result

def main():
    decode(string)
    
    

main()

Don't use 'string' as a variable name. It is the name of an important module.

ok, i replaced "string" with "cipher" but still getting the same error. thanks, but either way, I didn't import the module which makes string un-usable in that sense. But, whatever, still changed it.

This is the exact error I get:

in decode def cipher(code):
ValueError: substring not found

You didn't by any chance name this "string.py" did you? I was testing your code, and without thinking, named it "string.py". This is the name of an important module called automatically from python. If you have another with the same name, string.py can't find the substring() func it needs for index and rotate. Rename your program and don't forget to delete or rename any "string.pyc" files that might have been created by your IDE.

lol no, it's called hw3.py

AH its ok though, this apparently is wrong anyway, I'm supposed to rotate based on frequency, which is I have no clue how to do. Any tips?

OKOKOKOK, so i've gotten pretty far, and changed my code completeley..

import string

code = 'BJ YMJ UJTUQJ TK YMJ ZSNYJI XYFYJX, NS TWIJW YT KTWR F RTWJ UJWKJHY ZSNTS, JXYFGQNXM OZXYNHJ, NSXZWJ ITRJXYNH YWFSVZNQNYD, UWTANIJ KTW YMJ HTRRTS IJKJSXJ, UWTRTYJ YMJ LJSJWFQ BJQKFWJ, FSI XJHZWJ YMJ GQJXXNSLX TK QNGJWYD YT TZWXJQAJX FSI TZW UTXYJWNYD, IT TWIFNS FSI JXYFGQNXM YMNX HTSXYNYZYNTS KTW YMJ ZSNYJI XYFYJX TK FRJWNHF.'
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

countcode = 0.0
count = 0
dictionary = {}

for letter in alphabet:
        count = code.count(letter)
        countcode = countcode + count
        count = (count/countcode)
        dictionary[letter] = dictionary.get(letter, 0) + (count)


if count >= 12.702:
        code.replace(dictionary[letter],'e')



print dictionary
print countcode
print code

firstly...my frequencies are all off, I don't know why SOMEBODY PLEASE HELP

second..how can i replace a character from the dictionary with a specified character at a given frequency:

OKOKOKOK, so i've gotten pretty far, and changed my code completeley..

import string

code = 'BJ YMJ UJTUQJ TK YMJ ZSNYJI XYFYJX, NS TWIJW YT KTWR F RTWJ UJWKJHY ZSNTS, JXYFGQNXM OZXYNHJ, NSXZWJ ITRJXYNH YWFSVZNQNYD, UWTANIJ KTW YMJ HTRRTS IJKJSXJ, UWTRTYJ YMJ LJSJWFQ BJQKFWJ, FSI XJHZWJ YMJ GQJXXNSLX TK QNGJWYD YT TZWXJQAJX FSI TZW UTXYJWNYD, IT TWIFNS FSI JXYFGQNXM YMNX HTSXYNYZYNTS KTW YMJ ZSNYJI XYFYJX TK FRJWNHF.'
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

countcode = 0.0
count = 0
dictionary = {}

for letter in alphabet:
        count = code.count(letter)
        countcode = countcode + count
        count = (count/countcode)
        dictionary[letter] = dictionary.get(letter, 0) + (count)


if count >= 12.702:
        code.replace(dictionary[letter],'e')

this didn't work..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.