The asset-or-nothing European option pays at t = T the value of the stock when at time T that value exceeds or is equal to the exercise price E, and nothing if the value of the stock is below E. So, in mathematical terms:
$$V(S,T) = \left\{ \begin{array}{lr} S & \text{if}\quad S \ge E,\\ 0 & \text{if}\quad S < E. \end{array} \right. $$
The cash-or-nothing European option pays at t = T a fixed value B when at time T that value exceeds or is equal to the exercise price E, and nothing if the value of the stock is below E. So, in mathematical terms:
$$V(S,T) = \left\{ \begin{array}{lr} B & \text{if}\quad S \ge E,\\ 0 & \text{if}\quad S < E. \end{array} \right. $$
We know that the formulas for these options are the following: \begin{align} &\text{Cash-or-nothing call:}\quad c_{cn}=Be^{-rT}N(d_2),\\ &\text{Cash-or-nothing put:}\quad p_{cn}=Be^{-rT}N(-d_2),\\ &\text{Asset-or-nothing call:}\quad c_{an}=Se^{-qT}N(d_1),\\ &\text{Asset-or-nothing put:}\quad p_{an}=Se^{-qT}N(-d_1).\\ \end{align}
where $$ d_1=\dfrac{\ln(S/E)+(r-q+\sigma^2/2)(T-t)}{\sigma\sqrt{T-t}} $$ and $$ d_2=d_1-\sigma\sqrt{T-t}. $$
We also know that we are supposed to follow the derivation of Black-Scholes in order to derive these formulas but we are having trouble understanding how it differs from the derivation of Black-Scholes itself.