Reorders (reverse and rotate) the bytes of an u32 number, assuming the starting order is 1 2 3 4 (4 being at the top): if offset is 0, then reorder is 4 3 2 1 if offset is 1, then reorder is 1 4 3 2 if offset is 2, then reorder is 2 1 4 3 if offset is 3, then reorder is 3 2 1 4
(offset: usize)
| 139 | /// if offset is 2, then reorder is 2 1 4 3 |
| 140 | /// if offset is 3, then reorder is 3 2 1 4 |
| 141 | pub fn byte_reorder(offset: usize) -> Script { |
| 142 | assert!((0..4).contains(&offset)); |
| 143 | if offset == 0 { |
| 144 | script! { |
| 145 | OP_SWAP |
| 146 | OP_2SWAP |
| 147 | OP_SWAP |
| 148 | } |
| 149 | } else if offset == 1 { |
| 150 | return script! { |
| 151 | OP_SWAP |
| 152 | OP_ROT |
| 153 | }; |
| 154 | } else if offset == 2 { |
| 155 | return script! { |
| 156 | OP_SWAP |
| 157 | OP_2SWAP |
| 158 | OP_SWAP |
| 159 | OP_2SWAP |
| 160 | }; |
| 161 | } else |
| 162 | /* if offset == 3 */ |
| 163 | { |
| 164 | return script! { |
| 165 | OP_SWAP |
| 166 | OP_ROT |
| 167 | OP_2SWAP |
| 168 | }; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | /// Rotates the bits of a u32 number by rot_num |
| 173 | pub fn u32_rrot(rot_num: usize) -> Script { |
nothing calls this directly
no outgoing calls
no test coverage detected