Where do hash functions get their preimage resistance? [migrated]

I read through this answer and it seemed to make sense to me, but when I try to make a simpler answer to explain it to myself I lose something in the process.

Here is the much simpler hash function I wrote after reading the description of how MD5 works.

  1. Take in a single digit integer input as M
  2. Define A[0] to be some public constant
  3. for int i=1; i<=4; i++:
    A[i] = (A[i-1] + M) mod 10
  4. return A[4]

This hash function uses the message word in multiple rounds, which is what the answer says leads to preimage resistance. But with some algebra using mod addition we can reduce this "hash function" to just A[i] = (A[0] + i*M) mod 10.

A[1] = (A[0] + M) mod 10 A[2] = (A[1] + M) mod 10    //Substitute A[1] in      = ((A[0] + M) mod 10 + M) mod 10   // Distribute outer mod 10 in      = ((A[0] + M) mod 10 mod 10 + M mod 10) mod 10 // simplify mod 10 mod 10 to mod 10      = ((A[0] + M) mod 10 + M mod 10) mod 10    // Distribute inner mod 10      = ((A[0] mod 10 + M mod 10) mod 10 + M mod 10) mod 10  //factor mod 10 out      = ((A[0] mod 10 + M mod 10) + M) mod 10    // remove redudent paraens      = (A[0] mod 10 + M mod 10 + M) mod 10  // factor mod 10 in      = (A[0] mod 10 mod 10 + M mod 10 mod 10 + M mod 10) mod 10 // simplify mod 10 mod 10 to mod 10      = (A[0] mod 10 + M mod 10 + M mod 10) mod 10   // factor mods 10 out      = (A[0] + M + M) mod 10      = (A[0] + 2M) mod 1 // Repeat with A[3] to find A[3] = (A[0] + 3M) mod 10 and so on 

Because A[i] = (A[0] + i*M) mod 10 is not preimage resistant, I’m confused as to what action in a hash function gives it its preimage resistance. To phrase my question another way, if I wanted to write a super simple hash function, what would I need to include to be preimage resistant?

Can the Chronurgy Wizard’s Chronal Shift ability be used when a creature passes a saving throw with Legendary Resistance?

From Explorer’s Guide to Wildemount, the Chronurgy Wizard’s Chronal Shift ability says:

You can magically exert limited control over the flow of time around a creature. As a reaction, after you or a creature you can see within 30 feet of you makes an attack roll, an ability check, or a saving throw, you can force the creature to reroll. You make this decision after you see whether the roll succeeds or fails. The target must use the result of the second roll.

Using the adult red dragon as an example, Legendary Resistance reads:

If the dragon fails a saving throw, it can choose to succeed instead.

Specifically, here is the scenario:

  1. Wizard casts saving throw spell on Red Dragon
  2. Red Dragon rolls the saving throw and fails
  3. Red Dragon expends one use of legendary resistance to succeed on the saving throw
  4. Wizard uses their reaction to use Chronal Shift to force the dragon to reroll the saving throw
  5. Red Dragon rerolls the saving throw and fails
  6. Red Dragon expends a second use of legendary resistance to succeed the saving throw

In particular, is step 4 of this scenario a valid use of the Chronurgy Wizard’s Chronal Shift ability?

For transparency, this question is a rewrite of this closed question, having this meta post about its closure. In response, I made this meta post that is more generally concerned with re-asking questions that were closed per our dont guess the system policy. Please avoid any meta discussion on this post, instead relegating it to the relevant meta posts.

The froghemoth has both lightning resistance and Shock Susceptibility; is this an error? Are there other monsters like this?

In Volo’s Guide to Monsters, the Froghemoth (pg. 145) has resistance to lightning damage, but also has the Shock Susceptibility trait, which gives it various penalties whenever it takes lightning damage.

I find this hard to wrap my mind around from a creature biology standpoint, as well as from a gameplay point of view. Is this a mistake? Is there any precedent for a monster having this dual resistance and vulnerability?

Is Magic Resistance broken in Player Characters?

So, every time some feature, item or whatever allows a player character to have Magic Resistance, people seem to go crazy about it. It happened when the Yuan-Ti was released as a playable race in VGM, it happened recently when the Satyr was announced for Theros, and it happened around here with the possibility of allowing a player to get a pseudodragon as familiar.

I am asking because honestly I have never played with an Yuan-Ti, but in most of the campaigns I DM or play, I don’t see Magic Resistance showing up a lot or helping the players a lot. It is certainly a strong feature for monsters since parties will often contain spellcasters, but most creatures do not have magical effects or anything. So, the question is straight forward: is allowing a player character to get Magic Resistance as broken as I have seen people assume? Am I missing something?

For reference

Magic Resistance. You have advantage on saving throws against spells and other magical effects.

What are all the ways that stacking resistance becomes immunity by RAW?

In this supplement for Rise of Tiamat, on page 4, the properties of the "dragon mask" magic items are described, including this property (bold emphasis mine:

Damage Absorption. You have resistance against the mask’s damage type. If you already have resistance to that damage type from another source, you instead have immunity to that damage type. If you already have immunity to that damage type from another source, whenever you are subjected to damage of that type, you take none of that damage and regain a number of hit points equal to half the damage dealt of that type.

Off the top of my head, I cannot think of any other feature, be it class feature, racial feature or magic item, that allows multiple forms of resistance to stack and become immunity to either a damage type or a condition. Is this a unique feature of the dragon masks (I’m not so interested in the absorption part, just the stacking resistances), or are there are features or magic items RAW that allow stacked resistances to become immunity?

If your wild shaped form has damage resistance and you revert to your normal form, does your normal form take the halved damage?

Let’s say we had a druid with the Circle of the Moon archetype. They can use their wild shape feature to turn into an elemental as per their Elemental Wild Shape feature (PHB, p. 69):

Elemental Wild Shape
At 10th level, you can expend two uses of Wild Shape at the same time to transform into an air elemental, an earth elemental, a fire elemental, or a water elemental.

Those elemental creatures all have resistance to nonmagical bludgeoning, piercing and slashing damage, and some forms have other damage resistances too. Let’s say your elemental form was on 5 HP and you took 20 nonmagical slashing damage. Your elemental form would halve that damage to 10 damage. This exceeds the total HP the elemental form was on, and so you would revert back to your normal form, as per wild shape (PHB, p. 67):

… if you revert as a result of dropping to 0 hit points, any excess damage carries over to your normal form. For example, if you take 10 damage in animal form and have only 1 hit point left, you revert and take 9 damage.

Let’s assume that your normal form has no damage resistances. Does your normal form really take just 5 slashing damage, even though your normal form isn’t resistant to slashing damage, or would your normal form take 10 damage, since that’s what it would have been if it wasn’t halved by a resistance that no longer applies to your reverted form? Intuitively I think the normal form should take 5 damage, but the below related question’s answers (even through it’s the opposite scenario) would imply that it would take 10 damage.

Related (but the other way around, since that Q&A is talking about the normal form having the resistance, whereas I’m asking about the wild shaped form having the resistance): How does resistance/vulnerability/immunity interact with carryover damage after reducing Polymorphed (or Wild Shaped) form to 0 HP?

Damage reduction and damage resistance: how to calculate?

Assume a character has both damage reduction and damage resistance vs an incoming attack.

One example of damage reduction is the Heavy Armor Master feat:

While you are wearing heavy armor, bludgeoning, piercing, and slashing damage that you take from non magical weapons is reduced by 3.

One example of damage resistance is the blade ward cantrip:

You extend your hand and trace a sigil of warding in the air. Until the end of your next turn, you have resistance against bludgeoning, piercing, and slashing damage dealt by weapon attacks.

Let’s assume a character with both effects above is hit by a nonmagical weapon attack dealing slashing damage. The attack deals 10 damage. What happens:

  1. Damage reduction applies reducing damage to 7, then damage resistance (rounds down). Character takes 3 damage.
  2. Damage resistance applies, halving to 5, then damage reduction takes it to 2 damage.

A sustained spell should require multiples drain resistance checks?

We are playing a Shadowrun 5 campaign. When a mage cast a spell, it should roll a Drain resistance check. The GM is requiring multiple drain checks, one for each turn the mage sustain the spell (in case of sustained spells). But I don’t think that a spell requires multiples checks, just one right after casting the spell. What’s the correct rule?

What happens when a creature with vulnerability to a damage type has resistance to the same type imposed on it, or vice versa?

So, let’s imagine for a moment that two Fiend-patron Warlocks are fighting. One uses its Fiendish Resilience to get resistance to fire damage, but the other one casts the Hallow spell with the Energy Vulnerability effect to impose vulnerability to fire damage.

The description of the Fiendish Resilience feature:

Fiendish Resilience: Starting at 10th level, you can choose one damage type when you finish a short or long rest. You gain resistance to that damage type until you choose a different one with this feature. Damage from magical weapons or silver weapons ignores this resistance. (PHB 109)

And the extra effect of Hallow:

Energy Vulnerability: Affected creatures in the area have vulnerability to one damage type of your choice, except for bludgeoning, piercing, or slashing. (PHB 249)

Which trumps which in this scenario? Or do they cancel out and result in standard (1x) damage?

I’m sorry if this has already been asked; I didn’t see anything like it in the “Related Questions” or “Similar Questions” sections.

Also, bonus points:

  • If imposed vulnerability/resistance trumps innate vulnerability/resistance, how does it interact with immunity?