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 7719375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:24:04+00:00 2026-06-01T03:24:04+00:00

I need to write custom ord and chr functions. I’m writing a little program

  • 0

I need to write “custom” ord and chr functions. I’m writing a little program to apply a Caesar cipher to a message. What is the fastest way to do this?

The function “ord” only needs to take a character and then return the appropriate number. ‘A’ should return 0, ‘B’ should return 1, etc. Assume that we’re only going to use capital letters, so we only have 26 possibilities. I’d rather not write out 26 guards. Is there a better way to do this? Here’s how they’ll be used. The “chr” function should do the reverse.

caesarencipher::Int->Int->String->String
caesarencipher r s p = map chr . map encipher $ plaintext
    where
        plaintext = map ord p
        encipher p =  mod (r*p + s) 26

caesardecipher::Int->Int->String->String
caesardecipher r s c = map chr . map decipher $ ciphertext
    where
        ciphertext = map ord c
        inverser x | mod (r * x) 26 == 1 = x
                   | otherwise = inverser (x + 1)
        decipher c = mod ((inverser 1) * (c - s)) 26
  • 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-01T03:24:05+00:00Added an answer on June 1, 2026 at 3:24 am

    If you really want the fastest way to define custom versions of these functions, then just write out every possible pattern. You can pack multiple clauses onto a line by separating them with semicolons.

    However, I don’t see what you’ll gain. ord and chr aren’t any slower just because they handle all codepoints; Char already stores a complete Unicode codepoint. Indeed, ord should be basically free, and chr too (beyond the simple check for validity). So why not just apply the appropriate numeric offset to the standard ord and chr functions? (Note that even just writing out the patterns as I suggested above won’t omit error-checking entirely; GHC will throw an exception if a value is passed that none of your clauses handle.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a temporary Web-based graphical front-end for a custom server system.
I'm implementing a custom control and in this control I need to write a
Is there any need to use a custom buffer to either read or write
I need to write a program in ANSI C that will display the UTF-8
I need to write a custom web-scraper to mine some data. ?I know how
What is a NamespaceHandler? What is the need to write our custom NamespaceHandler? Please
I need to write a custom WPF control that should look like a ComboBox
I need to write a custom UrlRewriter using a HttpModule, in the moment of
I need write an update statement that used multiple tables to determine which rows
I need to write a regular expression to verify if a file input follows

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.