ArticleslgStudy

computer science

Crypt (C)

Crypt (C) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Crypt (C) rather than just read about it. In short: crypt is a POSIX C library function. It is typically used to compute the hash of user account passwords.

Key takeaways

  • Crypt (C) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Crypt (C) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Crypt (C) from memory before moving on to harder problems.

Reference excerpt

crypt is a POSIX C library function. It is typically used to compute the hash of user account passwords. The function outputs a text string which also encodes the salt (usually the first two characters are the salt itself and the rest is the hashed result), and identifies the hash algorithm used (defaulting to the "traditional" one explained below). This output string forms a password record, which is usually stored in a text file. More formally, crypt provides cryptographic key derivation functions for password validation and storage on Unix systems.

Relationship to Unix crypt utility There is an unrelated crypt utility in Unix, which is often confused with the C library function. To distinguish between the two, writers often refer to the utility program as crypt(1), because it is documented in section 1 of the Unix manual pages, and refer to the C library function as crypt(3), because its documentation is in manual section 3.

Details This same crypt function is used both to generate a new hash for storage and also to hash a proffered password with a recorded salt for comparison. Modern Unix implementations of the crypt library routine support a variety of hash schemes. The particular hash algorithm used can be identified by a unique code prefix in the resulting hashtext, following a de facto standard called Modular Crypt Format. The crypt() library function is also included in the Perl, PHP, Pike, Python (although it is now deprecated as of 3.11), and Ruby programming languages.

Key derivation functions supported by crypt Over time various algorithms have been introduced. To enable backward compatibility, each scheme started using some convention of serializing the password hashes that was later called the Modular Crypt Format (MCF). Old crypt(3) hashes generated before the de facto MCF standard may vary from scheme to scheme. A well-defined subset of the Modular Crypt Format was created during the Password Hashing Competition (PHC). The format is defined as: $<id>[$<param>=<value>(,<param>=<value>)*][$<salt>[$<hash>]] where

id: an identifier representing the hashing algorithm (such as 1 for MD5, 5 for SHA-256 etc.) param name and its value: hash complexity parameters, like rounds/iterations count salt: salt following the radix-64 alphabet (DES uses the decoded value) hash: radix-64 encoded result of hashing the password and salt The radix-64 encoding in crypt is called B64 and uses the alphabet ./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz which is different than the more common RFC 4648 base64

The PHC subset covers a majority of MCF hashes. A number of extra application-defined methods exist.

Original implementation using the password as a key The original implementation of the crypt() library function in Third Edition Unix mimicked the M-209 cipher machine. Rather than encrypting the password with a key, which would have allowed the password to be recovered from the encrypted value and the key, it used the password itself as a key, and the password database contained the result of encrypting the password with this key.

Traditional DES-based scheme The original password encryption scheme was found to be too fast and thus subject to brute force enumeration of the most likely passwords. In Seventh Edition Unix, the scheme was changed to a modified form of the DES algorithm. A goal of this change was to make encryption slower. In addition, the algorithm incorporated a 12-bit salt in order to ensure that an attacker would be forced to crack each password independently as opposed to being able to target the entire password database simultaneously. In detail, the user's password is truncated to eight characters, and those are coerced down to only 7-bits each; this forms the 56-bit DES key. That key is then used to encrypt an all-bits-zero block, and then the ciphertext is encrypted again with the same key, and so on for a total of 25 DES encryptions. A 12-bit salt is used to perturb the encryption algorithm, so standard DES implementations can't be used to implement crypt(). The salt and the final ciphertext are encoded into a printable string in a form of base64. This is technically not encryption since the data (all bits zero) is not being kept secret; it's widely known to all in advance. However, one of the properties of DES is that it was designed to be resistant to key recovery even in the face of known plaintext situations. It is theoretically possible that two different passwords could result in exactly the same hash. Thus the password is never "decrypted": it is merely used to compute a result, and the matching results are presumed to be proof that the passwords were "the same." The advantages of this method have been that the hashtext can be stored and copied among Unix systems without exposing the corresponding plaintext password to the system administrators or other users. This portability has worked for over 30 years across many generations of computing architecture, and across many versions of Unix from many vendors.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Crypt (C)

Start with the simplest possible case. Write down what Crypt (C) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Crypt (C) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Crypt (C) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Crypt (C)

In research
Crypt (C) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Crypt (C) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Crypt (C) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Broken cryptographic algorithms, Computer access control protocols, Cryptographic hash functions, so understanding it makes those chapters shorter.
In everyday life
Look for Crypt (C) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Crypt (C)” →

How to study Crypt (C) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Crypt (C) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Crypt (C) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Crypt (C) in simple terms?

crypt is a POSIX C library function. It is typically used to compute the hash of user account passwords.

Why does Crypt (C) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Crypt (C)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Crypt (C).

Tags

  • Broken cryptographic algorithms
  • Computer access control protocols
  • Cryptographic hash functions
  • Key derivation functions
  • Password authentication

Keep exploring