IPB

Welcome Guest ( Log In | Register )


2 Pages V  < 1 2  
Reply to this topicStart new topic
> python challenge
pebkac
post Mar 11 2008, 09:21 PM
Post #16


From Atlantis to Interzone


Group: Global Moderators
Posts: 2,512
Joined: 23-February 06
From: Somewhere in space and time
Member No.: 65



Here's a simple script I wrote to open a text file, increment all the letters in it by two and save them to another text file:

CODE
import sys
import string

in_file = open("encrypt", "r")
text = in_file.read()
in_file.close()

def increment(char, by=2): return chr(ord(char)+by)

out_text = ""
for char in text:
    if char.isalpha():
        if char.startswith(("y","z","Y","Z")):
            out_text = out_text + increment(char, -24)
        else:
            out_text = out_text + increment(char)        
    else:
        out_text = out_text + char
    
out_file = open("py.out", "w")
out_file.write(out_text)


--------------------
QUOTE (Spectatrix @ Oct 13 2006, 09:51 PM) *
Holy shit, pebkac, you're awesome!



"Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind." - Theodor Seuss Geisel (AKA Dr. Seuss)

"An idea that is not dangerous is unworthy of being called an idea at all." - Oscar Wilde
Go to the top of the page
 
+Quote Post
impala454
post Mar 11 2008, 10:17 PM
Post #17





Group: Members
Posts: 10,620
Joined: 23-February 06
From: Houston, TX
Member No.: 48



This could be a fun thread wink.gif

CODE
using System.IO;

class Program
{
    static void Main()
    {
        StreamReader sr = new StreamReader("inputfile.txt");
        StreamWriter sw = new StreamWriter("outputfile.txt");
        foreach (char c in sr.ReadToEnd())
        {
            sw.Write((char)((int)c+1));
        }
        sw.Close();
    }
}
Go to the top of the page
 
+Quote Post

2 Pages V  < 1 2
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 19th December 2025 - 10:03 PM
Skin made by: skeedio.com